-
Notifications
You must be signed in to change notification settings - Fork 116
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
How to transmit / upload files over API? #25
Comments
There is currently no native way to do this in Restivus, and the truth is, it's because I don't know how. I've looked into it briefly for my own applications, and it just hasn't been an immediate enough need for me to do any proper research. There are still a few basic features that I need to get in there (some fundamental REST stuff and some things for keeping code DRY), and then this will be on the top of my list after that. I'll go ahead and add it to the roadmap. If anyone knows anything about this please feel free to chime in. Any suggestions or resources on supporting this would go a long way. If you do the research, please post anything you find here, especially if there are any other meteor packages doing this right now. I thought that the [http-methods[(https://github.com/CollectionFS/Meteor-http-methods) package supported it, but I don't see anything in a quick scan of their readme. I actually work with both of the guys that made that package (just a happy coincidence I suppose), so maybe I'll just ask them when I see them later. They know infinitely more about file management in Meteor than I do, considering they worked on all the CollectionFS stuff. Maybe they can point me in the right direction. |
+1 for this, and also downloading files via the API - see #32. |
+1 |
Would love this. 👍 |
I have used restivus in combination with FSCollection to accept uploaded files via the API with code like
where |
@cuatromedios I'm going to try your approach, you should make a gist out of it if it works with the latest version. |
Or, post images as base64 to your Api endpoint, then store as base64 in a mongo collection. For GET, your API can give a base64 back from the mongo collection, which you can then draw on canvas or attach to img src in the client. Mongo has native support for storing images as base64. |
I'm using base64 type image and I cannot upload images morethan 750KB size, any ideas? |
How to do this in restivus,, I wanna make a server for handling a file upload from my android native java as client. Below is the code that's implemented in node js that i get from tutorial in internet. How to do like this below in meteor js especially with this library restivus var fs = require('fs'); module.exports = function(app) { app.get('/',function(req,res){ }); } app.get('/uploads/:file', function (req, res){ }); |
Meanwhile, created this gist with @cuatromedios response: https://gist.github.com/rapito/59d92e4a600c0e87ea48 |
@cuatromedios @rapito Here's a gist of what I have so far. But on my console I see |
+1 would love support for file uploads over the API. |
Hey folks! So sorry to go dark on this for so long. If I ever find the time to work on Restivus, I promise to address this (I'm currently working one job that pays the bills and also trying to simultaneously turn my own startup into something that pays some bills as well). I just don't seem to be able to find the time for Restivus nowadays. This issue has the |
How do I send the file to the API? I tried with the form and with the Meteor HTTP.post with the header 'content-type': 'multipart/form-data', but did not work. What is the correct way to send the file? |
Is there any update to this? FSCollection has been deprecated and now seems no solution. |
I found a solution that works for file upload using an HTTP POST endpoint. I attached the file using form-data (say in Postman, for testing purposes). Here's the tutorial that I adapted to restivus I am using FSCollection still, since it was already in my project as a dependency before it was deprecated. And here's my code
|
In my case @andrewash example don't work due some weird use of I do some work around tho solve problem. Restivus use JsonRoutes so i use same package in meteor to inject middleware function ( My example: https://gist.github.com/MartinBucko/f97e0649ca92cd266ca8edc2dca6548e See https://github.com/stubailo/meteor-rest/tree/master/packages/json-routes#adding-middleware how to use JsonRoutes.Middleware Hope this help someone. If i have more time i will like this add to restivuse in more advanced way. |
@MartinBucko your code worked for me. But since i dont use Coffescript, i converted it. (with decaffeinate) But i had to use |
I couldn't get @andrewash example to work either which is too bad because it would be a really nice way to handle this. In either case a simple solution that worked for me was to use
|
@cuatromedios How do you send photos from the client in order to make this work? |
Does smb know how to increase the limit of POST body size to enable more than 750KB?
Then I do not understand why request body becomes empty as soon as request body size exceeds ~750KB. |
Thank you @MartinBucko ,The solution in javascript language is here: (Tested on Meteor 1.10) upload-middleware.js
Once the middleware was executed you can get the data in your endpoint: Endpoints.js
You can test the different ways to send data from postman (form-data, x-www-form-urlencoded,raw with application/json header) and it must be work. Also, I added an endpoint to how download files en the readFile method is the following: FilesOperations.js
Note: My config file of Restivus is the following: config.js
|
I tried this solution but it says: |
In my application I need the capacity to accept files via a POST request, my app uses
yogiben:autoform-file
for file uploads. Is there a way to achieve this?The text was updated successfully, but these errors were encountered: