简体   繁体   中英

Parse Server S3 Images Upload Only Sometimes - Socket Issue

I have a Parse Server that is connected to Amazon S3. Sometimes, images are successfully uploaded from my app to S3. I can pull those down without issue. Sometimes, however, images cannot upload to S3. In my iOS app, I get these errors when the app is trying to upload the images:

在此输入图像描述

and this:

在此输入图像描述

Here's my parse server initlialization:

在此输入图像描述

POLICY ISSUE POSSIBILITY

I'm not sure what is happening. I think it might be something to do with S3 policies. I made my policy according to this . The policy looks like this:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Effect": "Allow",
        "Action": [
            "s3:*"
        ],
        "Resource": [
            "arn:aws:s3:::BUCKET_NAME",
            "arn:aws:s3:::BUCKET_NAME/*"
        ]
    }
 ]
}

APP TRANSPORT SECURITY POSSIBILITY

Another idea I have is that perhaps it has to do with App Transport Security which Apple enforces. Since I haven't set up SSL for HTTPS yet, I have to exempt the sample.elasticbeanstalk.com URL in my PLIST. Perhaps when utilizing the S3 adapter it goes to a different URL than sample.elasticbeanstalk.com which I also need to exempt in the PLIST. My S3 Adapter does set Direct Access == true if that matters. Since no App Transport Security error is appearing in my iOS app though, it probably isn't that. Just a thought.

BEFORE SAVE TRIGGER

I have a before save trigger on the object that I am uploading images for. None of the console.logs in my beforeSave trigger for it write when it can't upload so I don't think the issue lies here although it might.

MOST LIKELY SOURCE OF ERROR

My Elastic Beanstalk logs have this repeatedly stated:

2017/01/05 18:11:35 [error] 6993#0: *16609 client intended to send too large body: 3803408 bytes, client: , server: , request: "POST /parse/files/image.png HTTP/1.1", host: “name.elasticbeanstalk.com"

Why would the images be too large to upload? How do I overcome this?

QUESTION

Any idea what the issue is? . Thanks!

you've probably solved this by now... nevertheless, as you already mentioned - most likely it has to do with the provided Elastic Beanstalk logs. Though i cannot relate to the error logs concerning the socket problems, I almost faced the same issues migrating my ex-Parse-hosted apps some days ago.

The problem is the (nginx) environment configuration on Elastic Beanstalk which somehow only allows/handles files with a maximum size of around 1 MB by default (just my own estimation since you cannot get reliable and consistent information about that from AWS side).

But: you can overcome this limit by adding the following lines to the .config-file (if existing, otherwise create a new file eg 'app.config') in your Parse Server's .ebextensions-directory (if existing, otherwise create a directory namend '.ebextensions' at the top most position inside your Parse Server directory):

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

The '10M' in this example stands for a size of 10 MB - adjust this depending on your requirements (but keep in mind that Parse Server defines a maximum size for files too - not 100% about that, but I think it's 20 or 25 MB by default. You could set this as a param/option when initialising your Parse Server instance in index.js.).

Hope I could help someone :)

/m

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM