-
Notifications
You must be signed in to change notification settings - Fork 25
Consider how to handle file upload #102
Comments
I haven't tried it yet but any reason const multer = require('multer')
const upload = multer({ dest: 'uploads/' })
const fileService = {
create(data, params) {
// data is the file
return Promise.resolve({});
}
}
function setFile(req, res, next) {
req.body = req.file;
next();
}
app.post('/upload', upload.single('avatar'), setFile, fileService); Wouldn't work? |
@daffl the server side piece works just fine. I mean from the client side. Currently, you need to circumvent feathers-client and use the underlying REST lib (superagent, request, axios, etc.) directly in order to upload via multipart/form. You can't just set I'm also interested in exploring socket file upload. There seems to be a couple modules that do it in a non-feathers way, I wonder if we can adapt it (it's a great use of sockets imho). You can use these two: or this modules: Most file upload implementations use base64 encoding. For large images this can be expensive on memory, especially on mobile. There are also some interesting constraints with React Native, base64 encoding a big image and uploading in your JS thread locks the UI so ideally you want that part to happen on the native side and you just have a JS interface into it. |
How would you normally stream it in RN? I think feathersjs/feathers#384 might be related. |
Currently we are using this https://github.com/wkh237/react-native-fetch-blob. Working pretty well with multi-part but we're not stress testing with huge files. We're drastically shrinking the file size to save data when not on wifi. For streaming I'm not sure. I think you could use sockets for it. That issue is definitely related. On the server side, there is some sweet stuff happening with Multer. They have a streaming branch in the works ( How I got along that train of thought was specifically being able to transform files prior to saving them somewhere (ie. cropping before shipping to S3). Related: |
I'm going to close this in favour of continuing the discussion in the proposal for stream support at feathersjs/feathers#609 |
With the current client it's not that easy to upload files. You can't quite do a
create
via the rest client. Instead you need to use the underlying library. I'm a big fan of how superagent handles multipart requests.I think we should consider one of 3 options:
create
call, orattach
method that allows you to add files for a create call.The text was updated successfully, but these errors were encountered: