Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

javascript - Async image upload and trigger graphql subscription

I have a dilemma for which, hopefully, someone here can assist me with.

So in my app, I have a feed of news. A user can add a new news which has an image(just a url to the image from an external website). The dilemma is regarding how to upload that image to s3. So currently uploading that image from my web-server(nodejs) is basically making a request to that image url, getting the image from the body and uploading it to s3. And that works fine most of the time.

The problem is that sometimes the image url(from the external website) takes long to retrieve(sometimes more than 1s) and then upload.

Since I have the ability to notify my apollo graphql subscribers(for that new news item on the feed I just created) that an update has happened. The idea is to make that upload of the image async and then trigger the subscriptions when the response gets through. And just pass in the uploaded image, so it gets updated in the feed.

I have 3 options and I would like to have your input on which is best performance vise:

  • Upload the image just by calling a method called "uploadToS3"(which calls aws sdk and passes the image blob) and in the promise resolve callback notify the subscribers
  • Put the upload of the image in a nodejs worker thread and let it notify the subscribers once it uploads the image via the method "uploadToS3"
  • Create a AWS SQS queue which will trigger a lambda which will upload the image from an external url. But then I'm not sure how I will get the response from the lambda to my web-server, so I can notify the subscribers?
question from:https://stackoverflow.com/questions/65883541/async-image-upload-and-trigger-graphql-subscription

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...