- 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.
- but my function of uploading pictures is to decode it in the base64, background through front-end transmission, and then transfer it to disk.
- 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();
}
- 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?
- ask the boss to solve the problem.