Coder Social home page Coder Social logo

feathers-example-fileupload's Introduction

feathers-example-upload

A Feathers.js file upload example, using feathers-blob.

Features:

  • Simple feathers-blob example and REST client.
  • Example with multipart/form-data support and real-time client.

How to use it:

  • Clone or download it. git clone https://github.com/CianCoders/feathers-example-fileupload.git
  • $ cd feathers-example-fileupload
  • $ npm install
  • $ npm start
  • Visit http://localhost:3030/ for a simple feathers-blob example
  • Visit http://localhost:3030/dropzone.html for a dropzone example with socket.io client.
  • Enjoy.

feathers-example-fileupload's People

Contributors

alejandrogtz avatar denjohx avatar npmcdn-to-unpkg-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

feathers-example-fileupload's Issues

How to authenticate uploads

The article only explains how to send files as multipart via a simple form. However then i don't have any authentication(because the authentication header is missing). I want to be able to still use feathers client like app.service("uploads").create({uri:mynewUpload}). Is that even possible? Because the feathers client will likely not support multipart requests. Hence either one is encoding the data on the client OR use a simple form, but then loses all feathers mechanisms(no hooks, no authentication etc.). Isn't that right?

Retrieving files as binary via GET

Hello,

thank you very much for your guide, it helped me tons.

However I also need to be able to retrieve the files as normal binaries. How would you go about that (without utilizing the client)?

I tried to write a hook that converts the datauri back to binary and sets it as hook.result. This obviously doesn't work as you still get a json with just a binary string and content type set to application/json.

I'm still new to Feathers, hope I didn't miss anything.

question regarding example proceedings

I have a question concerning the example. I am new to feathersjs so it is probably something I misunderstood, but in the example, the function that take a file to turn it into a datauri for blobservice is called inside a BEFORE hook. I thought before hooks where called before the service, to witch it applies, run. So how can this before hook handle the file created by multer from multipart data (with the function call: multipartMiddleware.single('uri')) if this part of the code have not been executed yet?
Or is it than in the case of multiple middelware functions called into the app.use() function, the before hooks would be inserted between the second to last and the last function? (I thought it would be called before any middelware function called by app.use() )

And couldn't we do something like:

app.use('/uploads',
    blobService({Model: blobStorage})
);

app.service('/uploads').before({
    create: [
        function(hook) {
            if (!hook.data.uri){
                 multipartMiddleware.single('uri'),  //don't know how to call multer here has I don't know if hooks have access to req, res and next.
                 if ( req.file)
                 {
                    const file = req.file;
                    const uri = dauria.getBase64DataURI(file.buffer, file.mimetype);
                    hook.data = {uri: uri};
                 }
            }
        }
    ]
});

which should be proper as multer needs to be called only in the 'create' function of the service and not in the 'get' one for example

How do I customize the name of file?

I have few questions.

  1. How do I validate files ?
  2. How to customize file's name ?

seems like it takes ${hash(content)}.${extension(contentType)} as a file name. How do I change it manually? let's say the name like "user-avtar-123.png".
On feathers-blob documentation I found that I just need to pass extra id field to body for custom name but I don't understand where it is used.
`const blob = {
uri: getBase64DataURI(new Buffer('hello world'), 'text/plain')
}

blobService.create(blob).then(function (result) {
console.log('Stored blob with id', result.id);
}).catch(err => {
console.error(err);
});`

Question regarding the dropzone example

On the example using dropzone I see that the upload destination is defined as <form action="/uploads". I guess this means that dropzone would directly try to contact the 'SERVER_URL/uploads' url to upload the file(s). Right?
That means that dropzone would not use the feathers client defined above, with a socket.io connection, to make the upload but rather open a new classic http connection (without any authorization header) to perform the file upload. Is it correct or am I missing something?
If so, is there any way to reuse the socket opened by the feathers client to perform the upload (without necessarily using dropzone), so that I can benefit from the autorization attached to this socket connection, or is there no curent way to perform file upload directly through scket for now?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.