Skip to content

Unable save large file to S3 using Parse server #3532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kesongxie opened this issue Feb 19, 2017 · 14 comments
Closed

Unable save large file to S3 using Parse server #3532

kesongxie opened this issue Feb 19, 2017 · 14 comments

Comments

@kesongxie
Copy link

kesongxie commented Feb 19, 2017

I tried to save to S3 bucket using Parse, and it can be saved correctly when the file is small, such as 864.2KB. However, when the file is large, say 5MB, it complaints with a message saying: "The data couldn’t be read because it isn’t in the correct format"

I'm using the following code to save the the video file to the 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)
        }
    }

Besides, even when the small video file is indeed being saved to the S3, it contains an extension .bin instead of, for example .mp4. I wonder what's happening here
The url end up looking something like this

https://s3-us-west-1.amazonaws.com/sampleApp/19d5bce20f8b55te1b1b8f370212533e5_file.bin
@kesongxie
Copy link
Author

kesongxie commented Feb 19, 2017

Update: I have to use post["media"] = PFFile(data: data, contentType: "video/mp4"), now the video is correctly stored in the S3 with mp4 extension, and I can also stream it using AVPlayer, and now the remaining problem is the size, it seems I can't upload a video that is more than 1MB or something

@flovilmart
Copy link
Contributor

Probably a problem with the load balancer in front of parse-server or the maxUploadSize option.

@kesongxie
Copy link
Author

kesongxie commented Feb 19, 2017

@flovilmart can you point me to any resources that I can verify or change the maxUploadSize. I understand the the default max upload size is 20 MB, is that correct?

@flovilmart flovilmart reopened this Feb 19, 2017
@flovilmart
Copy link
Contributor

The default should be 20Mb, you're right, the option is passed directly to express body parser: https://github.com/ParsePlatform/parse-server/blob/d5940b17b6914f04462420812aed9efe54a2b37f/src/Routers/FilesRouter.js#L22

@kesongxie
Copy link
Author

kesongxie commented Feb 19, 2017

In this case, can I just set my environment variable the same as how I set the variable such as MASTER_KEY or APP_ID, etc, and I add a new environment variable called maxUploadSizewith its value equals to 20mb. Will this overwrite the default setting?

@flovilmart
Copy link
Contributor

flovilmart commented Feb 19, 2017

That should be possible with "PARSE_SERVER_MAX_UPLOAD_SIZE"

@kesongxie
Copy link
Author

Still complaining "The data couldn’t be read because it isn’t in the correct format." using saveInBackground when the file size is just 2.8MB

@flovilmart
Copy link
Contributor

What is complaining? The client or the server?

@kesongxie
Copy link
Author

kesongxie commented Feb 19, 2017

The output from the Xcode, also just found this on the log on ELB
2017/02/19 20:48:40 [error] 26869#0: *120 client intended to send too large body: 2771673 bytes, client: 172.31.20.12, server: , request: "POST /parse/files/file HTTP/1.1", host: "parseserver-bjqgv-env.us-east-1.elasticbeanstalk.com"

I think it may be the AWS that is setting the file size limit somewhere

@flovilmart
Copy link
Contributor

@kesongxie
Copy link
Author

Now it works after setting the client_max_body_size to a larger value. See how you set the value, you can refer it here http://websistent.com/fix-client-intended-to-send-too-large-body-nginx-error/

@HackShitUp
Copy link

@flovilmart could the default should be 20Mb file size be modified from the index.js file from the example parse server?

@flovilmart
Copy link
Contributor

You should set it in your configuration object

@omarojo
Copy link

omarojo commented Aug 13, 2020

I have the same issue but in Heroku which I think it uses Express. I set the server property.
Im still getting the error, any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants