2017-02-19 55 views
0

我嘗試使用Parse Server保存到S3存儲桶,並且在文件較小時可以正確保存,例如864.2KB。但是,當文件很大時,比如說5MB,它會抱怨帶有一條消息:「數據無法讀取,因爲它的格式不正確」使用Parse服務器無法將大文件保存到S3

我正在使用以下代碼來保存視頻文件到S3

func saveVideo(withVideoURL url: URL){ 
     let post = PFObject(className: "Post") 
     post["caption"] = "Out of the game for 6 months, but back with vengeance. Meet your 2017 AO Men's champion" 
     do{ 
      let data = try Data(contentsOf: url) 
      print(data) 
      post["media"] = PFFile(data: data) 
      post.saveInBackground { (success, error) in 
       if success{ 
        print("video saved") 
       }else{ 
        print("failed") 
        if error != nil{ 
         print(error!.localizedDescription) 
        }else{ 
         print("erorr is nil") 
        } 
       } 
      } 
     }catch let error as NSError{ 
      print("can't read") 
      print(error.localizedDescription) 
     } 
    } 

此外,即使在小的視頻文件確實被保存到S3,它包含一個擴展名爲.bin代替,例如.MP4。我不知道這裏發生了什麼 的URL最終看起來像這樣

https://s3-us-west-1.amazonaws.com/sampleApp/19d5bce20f8b55te1b1b8f370212533e5_file.bin

回答

1

你需要規定的內容類型。你可以這樣做是這樣的:

post["media"] = PFFile(data: data, contentType: "video/mp4") 
+0

非常感謝你,我是Parse服務器的新手。現在小文件被正確保存到S3,我相信我無法上傳默認大於1MB的視頻,這是正確的嗎?我不知道這是導致問題的解析結束或S3,任何幫助表示讚賞 –

+0

看看你的分析服務器中的maxupload設置,看看它的設置。默認值應爲20mb – Cliffordwh

+0

我試圖找到我當前正在部署的分析服務器的maxupload位置。我試圖谷歌在哪裏可以設置maxupload,但沒有運氣。我試圖檢查index.js,但它不在那裏。你能否給我提供一些指導,我可以在哪裏檢查並修改它? –

1

parse-server索引文件的下面設置將幫助您:

var bodyParser = require('body-parser'); 
app.use(bodyParser.json({limit: '20mb'})); 
app.use(bodyParser.urlencoded({limit: '20mb', extended: true})); 

如果使用的是彈性魔豆,你必須有一個內部的名爲files.config文件文件夾.ebextensions,以下內容。

files: 
/etc/nginx/conf.d/proxy.conf: 
    content: | 
     client_max_body_size 20M; 

這解決了我的問題。

相關問題