Skip to content
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

500 Error: Unable to open Image (octet-stream). Image in sub-folder, fails w/ Query Params #20

Open
warrenmcquinn opened this issue Jan 13, 2018 · 4 comments

Comments

@warrenmcquinn
Copy link

warrenmcquinn commented Jan 13, 2018

This is a Bug Report

Description

For bug reports:

  • What went wrong?
    When I make an HTTP request to the serverless url, to resize an image in a sub-folder, with query parameters, I get a 500 error:
`"errorMessage": "{\"statusCode\":500,\"body\":\"{\\\"message\\\":\\\"convert: unable to open image `octet-stream:-': Read-only file system @ error/blob.c/OpenBlob/2643.\\n\\\"}\"}"`

When I don't use query params, the image downloads right away.

  • What was the config you used?
    serverless.yml with my personal bucket.
    I've set the Binary type on the gateway to /.

  • What stacktrace or error message from your provider did you see?
    I set up APIGateway logs in CloudWatch using the guide posted in Query Param - failed #17

Similar or dependent issues:

Additional Data

Here's the CloudWatch log:
image

@warrenmcquinn
Copy link
Author

warrenmcquinn commented Jan 13, 2018

Update: I tried with an image in the root of the bucket and it works! Great! However, for my use-case, it'd be best if I could pull from a sub-directory in the bucket.

It's probably something in functions/getImage/index.js that I can tweak.

@warrenmcquinn warrenmcquinn changed the title 500 Error: Unable to open Image (octet-stream). Only fails w/ Query Params 500 Error: Unable to open Image (octet-stream). Image in sub-folder, fails w/ Query Params Jan 13, 2018
@marcusmolchany
Copy link
Collaborator

hey @warrenmcquinn! thanks for opening an issue. @nicholasgubbins and i are pretty busy right now, so can't give you an exact date when we'll get to this one. if you have any ideas feel free to post to this issue or open a PR and we'll take a look.

@WyrmxD
Copy link

WyrmxD commented Mar 26, 2018

Hi, I have been dealing with a similar issue in another project and solved it by using the resultant S3 image inside the getObject() callback function instead of using .createReadStream().
In addition, to upload with gm.stream() avoid using file_type as param.

function gmCreator(asset, bucket, resize_options) {
  // function to create a GM process
  return new Promise((resolve, reject) => {
    try {
      s3.getObject({ Bucket: bucket, Key: asset }, (err, data) => {
        if (err) return reject(err);

        const func = gm(data.Body);
        ...
        return resolve(func);
      });
    } catch (err) {
      return reject({ statusCode: 500, body: `{"message":"${err.message}"}` });
    }
  });
}

function uploadToS3(destination, bucket, mime_type, storage_class, gm) {
  return new Promise((resolve, reject) => {
    try {
      ...

      gm.stream((err, stdout, stderr) => {
      ...
      });
    } catch (err) {
      return reject({ statusCode: 500, body: `{"message":"${err.message}"}` });
    }
  });
}

Hope this helps!

@atodhruv
Copy link

var params = {
Bucket: 'bucketname',
Body: image,
ContentType: file.mimetype,
Key: filename,
ACL:'public-read'
};
var res = await s3.putObject(params).promise();

--- Put ContentType of file

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