The use of OSS object Storage in Aliyun

  1. in order to expand the following page, I want to migrate the static resources of the existing project and upload files to Aliyun"s OSS.
  2. but my function of uploading pictures is to decode it in the base64, background through front-end transmission, and then transfer it to disk.
  3. there is a method uploadFile () in the oss class
    /**
     * 
     *
     * @param string $bucket bucket
     * @param string $object object
     * @param string $file 
     * @param array $options
     * @return null
     * @throws OssException
     */
    public function uploadFile($bucket, $object, $file, $options = NULL)
    {
        $this->precheckCommon($bucket, $object, $options);
        OssUtil::throwOssExceptionWithMessageIfEmpty($file, "file path is invalid");
        $file = OssUtil::encodePath($file);
        if (!file_exists($file)) {
            throw new OssException($file . " file does not exist");
        }
        $options[self::OSS_FILE_UPLOAD] = $file;
        $file_size = filesize($options[self::OSS_FILE_UPLOAD]);
        $is_check_md5 = $this->isCheckMD5($options);
        if ($is_check_md5) {
            $content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true));
            $options[self::OSS_CONTENT_MD5] = $content_md5;
        }
        if (!isset($options[self::OSS_CONTENT_TYPE])) {
            $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object, $file);
        }
        $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
        $options[self::OSS_BUCKET] = $bucket;
        $options[self::OSS_OBJECT] = $object;
        $options[self::OSS_CONTENT_LENGTH] = $file_size;
        $response = $this->auth($options);
        $result = new PutSetDeleteResult($response);
        return $result->getData();
    }
  1. requires three parameters, but the file I decode by base64 is supposed to have no path, so how can I use the upload function of oss without modifying the existing function?
  2. ask the boss to solve the problem.
Mar.12,2021

. You can decode it, save it, and then send it to OSS.


method does not allow uploadFile () to transfer local files. Oss also has a putObject () method, which is used to transfer in-memory data directly. In my previous project, As3 HttpRequest directly transferred base64 data to the backend to get the data that can be directly passed in.


oss has a web direct transmission function, which is more cool


check out this http://www.thinkphp.cn/code/4.

.
Menu