-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Upload image issue #464
Comments
@dfloresgonz did you ever get this working? I'm running into the same issue. |
@evangow I read that sls offline doesnt support binary types so it will never work, but only offline. I used base64 to make it work on local env. |
@dfloresgonz Are you converting it to base64 on the client side, then sending it to the server? Or, are you using something like the the gist linked below to parse the event and pass it onto serverless-http? Would you happen to have a code sample or gist you could share if you're doing it on the server side? I think I could probably figure it out on the client side, but I've been banging my head against the wall for hours looking through issues trying to sort this out. Parser Gist: https://gist.github.com/lteacher/9ef1c7bc5908418b30a18719521ff3c7#file-parsers-js-L12-L41 |
same here using curl -X POST -F 'file=@/home/jan/figub/pass.mp3;type=audio/mpeg' localhost:3333/upload -H "Content-Type: audio/mpeg" --verbose -H "Accept: audio/mpeg" |
With both |
Same here, cannot get it working, we looked through all the other code time after time without understanding what was happening. It would be good to at least throw something if it is not supported - took us more than a day to find this problem. |
We would gladly accept a PR on this. It shouldn't be much, just a Hapijs tweaking. |
FYI - I chose a different architecture. The lambda now just requests a temporary URL from my file bucket. The file bucket can be hidden behind an internal (transparent) redirect. |
I have encountered this issue and after extensive investigation, I found that https://github.com/dherault/serverless-offline/blob/master/src/index.js#L490 causes the issue. If I am trying to upload an image via It was added with #394 as a workaround? As there behavior that binary data was converted to a utf8 string. At least from initial testing, it seems that serverless offline works fine without 490 line. Maybe @dherault and @lteacher @daniel-cottone could comment if it's still required? |
If the line is removed then i assume it would work, because the line does some magic check to ensure the Actually I haven't been using serverless for 2 years but we still have a service running that parses multi-part form data, though it was using an old branch.... I did switch to the latest So regarding the above question, @arnas I also removed the line to see and as expected it worked just fine for me. That wasn't too surprising though because the check added was because of the I also spent a bit of time checking out what the whole problem is around here and it was painful... I guess at the end of the day the issue seems to come down to the encoding (since I wasn't able to get an exact answer with code links to provide). So probably for most of the above, its something like... an issue because the parsing magic is done on pipe and the encoding has been set to For sure its just the above referenced line that converts to string, so if its removed and it doesn't break whatever that old issue was then it would be ok. Otherwise you could try setting the encoding, there is some check that happens for if it is an actual buffer so it would probably still work both online and in offline... So summary try locally setting the encoding... In this gist the |
Well, it seems that this issue only appears for images, my colleague has tested and for example, uploading .txt works fine. It's a bit strange but from my finding, only images are affected. @lteacher I have checked the pr #224 and at least form the first look seems that toString() is unnecessary as to prevent hapis.js from parsing payload you can simply set payload to parse to |
@arnas sorry I dont get exactly what you mean with the last sentence. Problem History
Fixing in this repoSo to resolve the issue based on what you said above then the best thing is to not do any Fixing original author issues (assuming the fix is not done here in rep)
Also for original author if using wrapping packages with this kind of thing like the file data etc you need to check closely everywhere on the packages you are using like this doc over here. As I recall (but might have changed over last 2 years) you can only get binary content to AWS lambda functions in @arnas I assume that you have success already on AWS and that you use something like |
@lteacher I have update the wording of my previous comment last sentence. For fixing repo I believe that would be the best way. I am hoping that removing toString while hapi payload parse is to false will be enough. I will look into it if I have time. @lteacher I am using serverless-http, but I havent deployed it to aws as I amasuming it will work without much problem as atleast from documentation aws api gateway supports that https://aws.amazon.com/about-aws/whats-new/2016/11/binary-data-now-supported-by-api-gateway/ . |
@arnas oh well should be np if using that Actually I was thinking of this again for some reason and I had another look and noticed that the Theres a velocity template method too seems to assume the payload is json so dunno about that since sometimes its not already, otherwise could be able to just even move that stringifying stuff into the relevant scope where its needed which is like if it needs to be parsed per last reference? |
@lteacher I have a bit of debugging and from the first look it seems that this issues is not only from serverless-offline side. tl;dr the bug happens because Suggestions for solution
I could create a pr for a first point if this approch is acceptable with lib maintainers. Side note rawPayload is always equal to https://github.com/dherault/serverless-offline/blob/master/src/index.js#L490 |
Hey @arnas I think that you are missing some setup on AWS side. If you want to use binary content you need to do some different setup per these docs: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html Thats why I posted this thing from I knew about that If you look here in this gist you can see the actual property that your aws lambda-proxy binary content enabled handler will receive on the event. That is not a magical value I added for the gist, sadly that is an AWS thing that gets attached to the event. I actually don't use In summary I think you can change your AWS setup to correctly handle binary content, then you are going to start recieving |
I'm running into this issue using serverless-http + serverless-offline and multer-s3 for handing multipart/form-data when uploading images. @lteacher do you have a recommendation for getting serverless-offline to correctly handle this? My service works when deployed on AWS through api-gateway. For local development it is not.. Referring to your last comment above: "Then to get serverless-offline working is where the actual issues are left because it doesn't do the base64 encoding magic that the AWS stuff is doing so thats all this entire issue so far." |
@hqnarrate Sorry im just not up to date on this issue any more, there seems to be a PR #784 that was working to address this somewhat through the config options. Looking back over the comments it does seem like there is a way to refactor the offending line out but I just don't have any time to investigate that at the moment and I don't use any of the packages mentioned in these issues except Maybe @cmuto09 can give an update on where the PR referenced above is at, it looks like it needs rebasing at minimum. |
@hqnarrate @lteacher a bit of a problem is that @cmuto09 PR depends on the https://www.npmjs.com/package/serverless-apigw-binary plugin. but it seems |
@dnalborczyk - i was not clear. My service is working fine when deployed to AWS environment by setting the apiGateway.binaryMediaTypes correctly. It is when I'm running on offline mode with 'serverless offline start', my uploads would become corrupted. |
@hqnarrate sorry, I think I haven't been clear. 😄 I knew what you meant. The links above are pointers for me (or anyone else getting to it) for the implementation. |
@dnalborczyk Any update or workarounds on this issue? |
My solution: https://stackoverflow.com/a/61003498/9585130 Just add this to serverless.yml.
And I'm uing |
I had a similar issue with using serverless-offline + aws-serverless-express + multer It said whereas serverless-http has no problem. I made a simple example, upload-to-serverless-offline I could confirm that aws-serverless-express-binary is working as @abinhho mentioned here |
did anyone found the solution on this issue as uploading a form-data with pdf attached, on using multer , getting buffer size increased where as when i run same on node work's properly i.e without serverless. |
I can confirm the following setup does not work in "apollo-server": "^3.1.2",
"apollo-server-express": "^3.1.2",
"apollo-server-lambda": "^3.1.2",
"graphql-upload": "^12.0.0",
"serverless-offline": "^8.0.0", provider:
name: aws
runtime: nodejs14.x
apiGateway:
binaryMediaTypes:
- '*/*'
plugins:
- serverless-offline
- serverless-webpack |
How do you use "apollo-server-express": "^3.1.2" and "apollo-server-lambda": "^3.1.2" together? I saw your comments on this thread: jaydenseric/graphql-upload#155 (comment)
|
Please disregard For the sake of this issue apollo-server-express is irrelevant. I am hosting as mentioned from vaunus in the other topic. |
Thank you so much bro it works for me, I was stuck in this issue for couple of |
Are you sure there will no way to work in serverless offline. Might be I am also having same issue https://stackoverflow.com/questions/69810751/image-file-is-not-viewing-uploaded-by-s3 |
@UmerMIB can you share your handler to run Graphql with AWS Lambda? I'm using apollo-server-lambda and it's working but I couldn't run the mutation to save images in S3 correctly. I have that config with apiGateway in serverless.yml too. |
The schema
@mateo2181 is it enough code to share? |
Thanks so much @UmerMIB! Yes, actually my handler is quite similar to that one. I think the problem is with serverless. I'm testing with Firecamp to be able to send images, I send two variables (file and petId) but when I check the logs in CloudWatch I see: I have my serverless with the params that @kirankjolly comments above. |
Is there a workaround on this? |
For whomever is still messing around with this, small advice, is not worth it. You will shortly realize that lambdas have 6MB upload limits, so you better start to look into alternatives. This dude put together a good article: https://theburningmonk.com/2020/04/hit-the-6mb-lambda-payload-limit-heres-what-you-can-do/ |
Why is it not worth it, my customer has to upload an excel that I have to process, so instead of having a simple function receive a few hundred kB files, I have to deal with s3, send him a presigned url or hook into s3... Also considering that's something that works just fine on AWS, it just doesn't work locally |
any update on this? This is still a valid issue. |
BTW, I was patching for my own purpose - request.payload = request.payload && request.payload.toString(encoding);
+ if (request.payload && encoding !== 'binary') {
+ request.payload = request.payload.toString(encoding);
+ } |
@kennyhyun patch also worked for me. Thanks! |
@kennyhyun this works for me as well! |
Can you create a PR for this to be merged? |
In fact, I think the best is to add a section in the serverless-offline configuration to let the user self define how the payload should be encoded based on the content type. |
basically, this package is mainly for testing serverless (for example lambda) locally. so this package would be enough to support usual way for serverless functions. I believe it is discouraged to send any binary data to serverless functions. I was doing this in a dodgy way to use this package in some special case, not only for testing. if someone need this, I think it should take their own risk. so I won't send a PR. I agree with this BTW
|
Thank you, works perfectly in v13.3.3! Edit : This PR appears to fix the issue. :-) |
Fixed by #1776 |
My image seems to be corrupted when uploaded to server, It only works with .txt files.
I'm using sls 1.27, EspressJS and multiparty
Is there a way to upload images without any problems?
Thanks.
The text was updated successfully, but these errors were encountered: