增加了手机操作端
This commit is contained in:
@@ -81,6 +81,11 @@ class FileStorageService
|
||||
}
|
||||
|
||||
public function putContents(string $relativePath, string $content): void
|
||||
{
|
||||
$this->putContentsWithMimeType($relativePath, $content);
|
||||
}
|
||||
|
||||
public function putContentsWithMimeType(string $relativePath, string $content, string $mimeType = ''): void
|
||||
{
|
||||
$relativePath = $this->storagePath($relativePath);
|
||||
|
||||
@@ -94,10 +99,14 @@ class FileStorageService
|
||||
file_put_contents($tmpFile, $content);
|
||||
|
||||
try {
|
||||
$options = $mimeType !== '' ? [
|
||||
OssClient::OSS_CONTENT_TYPE => $mimeType,
|
||||
] : null;
|
||||
$this->ossClient()->uploadFile(
|
||||
$this->configService()->bucket(),
|
||||
$this->configService()->objectKey($relativePath),
|
||||
$tmpFile
|
||||
$tmpFile,
|
||||
$options
|
||||
);
|
||||
} finally {
|
||||
if (file_exists($tmpFile)) {
|
||||
@@ -118,7 +127,7 @@ class FileStorageService
|
||||
|
||||
try {
|
||||
$key = $this->configService()->objectKey($relativePath);
|
||||
$this->qiniuUploadFile($tmpFile, $key);
|
||||
$this->qiniuUploadFile($tmpFile, $key, $mimeType !== '' ? $mimeType : 'application/octet-stream');
|
||||
} finally {
|
||||
if (file_exists($tmpFile)) {
|
||||
@unlink($tmpFile);
|
||||
@@ -273,18 +282,18 @@ class FileStorageService
|
||||
);
|
||||
}
|
||||
|
||||
private function qiniuUploadFile(string $filePath, string $key): void
|
||||
private function qiniuUploadFile(string $filePath, string $key, string $mimeType = 'application/octet-stream'): void
|
||||
{
|
||||
$token = $this->qiniuAuth()->uploadToken($this->configService()->qiniuBucket(), $key);
|
||||
try {
|
||||
[$ret, $err] = $this->qiniuUploadManager()->putFile($token, $key, $filePath);
|
||||
[$ret, $err] = $this->qiniuUploadManager()->putFile($token, $key, $filePath, null, $mimeType);
|
||||
} catch (\Throwable $e) {
|
||||
$err = $e;
|
||||
}
|
||||
|
||||
if ($err !== null && $this->shouldRetryQiniuWithoutHttps($err)) {
|
||||
try {
|
||||
[$ret, $err] = $this->qiniuUploadManager(false)->putFile($token, $key, $filePath);
|
||||
[$ret, $err] = $this->qiniuUploadManager(false)->putFile($token, $key, $filePath, null, $mimeType);
|
||||
} catch (\Throwable $e) {
|
||||
$err = $e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user