瀏覽代碼

视频不能上传的问题解决了 ,另外上传大小限制到了10M

Mike 8 年之前
父節點
當前提交
8b3cdd756d

+ 2 - 3
server/app/Helper/AttachmentHelper.php

xqd xqd
@@ -19,10 +19,8 @@ trait AttachmentHelper
      * @param array $mimeType   文件mime类型限制,默认不限
      * @return array|string|int 返回:md5字串|ErrorCode或[md5字串|ErrorCode]
      */
-    public function uploadAttachment(Request $request, $key, $tag = 'files', $size = 2 * 1024 * 1024, array $mimeType = []) {
-        \Log::info("key:".$request->hasFile($key));
+    public function uploadAttachment(Request $request, $key, $tag = 'files', $size = 10 * 1024 * 1024, array $mimeType = []) {
         if ($request->hasFile($key)) {
-            \Log::info("key:".$key);
             $rel_path = '/upload/' . $tag . '/' . date('Ymd');
             $path = public_path() . $rel_path;
             if (!file_exists($path)) {
@@ -53,6 +51,7 @@ trait AttachmentHelper
                 }
 
                 $fileMimeType = $file->getMimeType();
+                \Log::info("fileMimeType:".$fileMimeType);
                 if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
                     $result[$idx] = ErrorCode::ATTACHMENT_MIME_NOT_ALLOWED;
                     continue;

+ 4 - 4
server/app/Http/Controllers/Api/V1/AttachmentController.php

xqd xqd xqd
@@ -48,7 +48,7 @@ class AttachmentController extends Controller
      * @apiPermission none
      * @apiVersion 0.1.0
      * @apiParam {string} tag 附件标签 avatar video dream
-     * @apiParam {File} file 附件(可以多个,使用file.xxx,可返回多个)[默认大小2M, 类型图片]
+     * @apiParam {File} file 附件(可以多个,使用file.xxx,可返回多个)[默认大小【10M】, 类型图片png jpg gif,视频类型mp4]
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
      * {
@@ -56,8 +56,7 @@ class AttachmentController extends Controller
      *     "code": 0,
      *     "message": "",
      *     "data": [
-     *         "file_123": "http://localhost/web/attachment/f72e7dad80f597ed6621a009e82243ad",
-     *         "file_456": "http://localhost/web/attachment/215a5f8307a015ecc35c80cb04d8590f"
+     *         "file": "http://localhost/web/attachment/f72e7dad80f597ed6621a009e82243ad",
      *     ]
      * }
      * @apiErrorExample {json} Error-Response:
@@ -100,10 +99,11 @@ class AttachmentController extends Controller
             return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '', $validator->messages());
         }
 
-        $result = $this->uploadAttachment($request, $request->get('file'), $request->get('tag'), 4 * 1024 * 1024, [
+        $result = $this->uploadAttachment($request, $request->get('file'), $request->get('tag'), 10 * 1024 * 1024, [
             'image/jpeg',
             'image/png',
             'image/gif',
+            'video/mp4',
         ]);
         if (is_array($result)) {
             return $this->api($result);