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

File upload through API proxy? #393

Open
allspain opened this issue Aug 30, 2014 · 6 comments
Open

File upload through API proxy? #393

allspain opened this issue Aug 30, 2014 · 6 comments

Comments

@allspain
Copy link

So I'm trying to upload a file through the apiProxy, and obviously it doesn't work out of the box because it doesn't look like the apiProxy or rest_adapter are intended to handle this out of the box. The file is succesfully uploaded to the express server (it's in the req.files) but its not being proxied over to the api because the api doesn't care about the files at all. What would be the best way to do send this over to our API server?

It seems like attaching it the api request as form data would be the best way, but I haven't had any success doing this. Is there any way to simply proxy the multiform data from express to the api server, sounds like there isn't because express just handles the file upload for you and I'm not you can easily access/disable that for proxying.

Anyone had any thoughts or has anyone come across this? Help? Does this make sense or am I losing my mind.

@bigethan
Copy link
Contributor

We've worked around this (to file uploads, bot other user interaction methods) by setting up a custom route on our express server that's handled by middleware to process the request. App is available via req.rendrApp so that you can then access the Rendr world within your middle ware to do what you need to do once the file is on the server (e.g.: move file to S3, get path of file, then POST that with the form data to the API. Or something)

@saponifi3d
Copy link
Contributor

I'm going to investigate modifying the base ApiProxy to allow for files to pass through as well, I remember investigating this a while ago and was able to find https://github.com/rendrjs/rendr/blob/master/server/data_adapter/rest_adapter.js#L119 which is where the files attribute on the request is being dropped.

Hopefully, I'll have a fix out for this in a PR in not too long (this week or next).

@azriel46d
Copy link

Has there been any update on this? or @saponifi3d did you manage to get a fix?

@nathanwelch
Copy link

For what it's worth, we implemented this by extending rendr's rest_adapter and overriding the apiDefaults method. After calling the parent's apiDefaults method we check for the existence of api.files and then construct a formData object as seen in the request docs here: https://github.com/request/request#forms . This also requires an update to a newer version of request so you can pass in formData like this. The version that rendr is on (2.40) requires you to have access to the return value of a call to request which would require modification of the request method in rendr's rest_adapter. We upgraded to request 2.49 and haven't noticed any issues yet. I think the functionality was added around 2.45 or so.

@saponifi3d Not sure how you were going to implement this, but if you haven't done so already and this seems reasonable, I could put together a PR for it this weekend.

@saponifi3d
Copy link
Contributor

@nathanwelch, if you have time to this weekend that'd be awesome. I upgraded request to 2.51 in this pull request and didn't run into any problems with it.

Thanks! let me know if you run into any issues

@saponifi3d
Copy link
Contributor

@nathanwelch - i just merged the update to pull in request v2.51. if you haven't had any time to look at it over this weekend, i can try to knock something out this afternoon.

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

No branches or pull requests

6 participants