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

Support DataURI (Base64) uploads #192

Closed
dr-dimitru opened this issue Aug 20, 2016 · 20 comments
Closed

Support DataURI (Base64) uploads #192

dr-dimitru opened this issue Aug 20, 2016 · 20 comments
Milestone

Comments

@dr-dimitru
Copy link
Member

No description provided.

@dr-dimitru dr-dimitru added this to the v.Next milestone Aug 20, 2016
@dr-dimitru
Copy link
Member Author

This will be useful after file is changed on the client and returned as DataURI, for example image changed in canvas

@dr-dimitru
Copy link
Member Author

Please vote if you need this feature

@renatomattos2912
Copy link

+1

dr-dimitru added a commit that referenced this issue Aug 24, 2016
 - Support upload directly `base64` and `dataURI` strings
example:
```js
FilesCollection#insert({
   file: 'data:image/png,…’,
   isBase64: true, // <— Mandatory
   fileName: ‘pic.png’, // <— Mandatory
   type: ‘image/png’ // <— Mandatory
});
```
dr-dimitru added a commit that referenced this issue Aug 24, 2016
 - Compatibility with `Meteor@1.4.1.1`
 - Fix: #196 (use inline WebWorker if client has support, with fallback)
 - Implement: #192 (upload file as base64)
 - Closing: #182 with [React Integration
Example](https://github.com/VeliovGroup/Meteor-Files/wiki/React-Example)
, thanks to [@vtocco](https://github.com/vtocco)
 - Minor DemoApp update
@dr-dimitru dr-dimitru mentioned this issue Aug 24, 2016
dr-dimitru added a commit that referenced this issue Aug 24, 2016
v1.7.1
 - Compatibility with `Meteor@1.4.1.1`
 - Fix: #196 (use inline WebWorker if client has support, with fallback)
 - Implement: #192 (upload file as base64)
 - Closing: #182 with [React Integration Example](https://github.com/VeliovGroup/Meteor-Files/wiki/React-Example), thanks to [@vtocco](https://github.com/vtocco)
 - Minor DemoApp update
@dr-dimitru
Copy link
Member Author

Implemented in v1.7.1, see example

@renatomattos2912 could you please test it on your end, and give some feedback?

@renatomattos2912
Copy link

@dr-dimitru of course, i will do this now.

@renatomattos2912
Copy link

@dr-dimitru it works pretty well. Thanks to be so fast in this feature.

@dr-dimitru
Copy link
Member Author

@renatomattos2912 , thank you for vote and for choice this package for file uploads

Please, support this project by:

@renatomattos2912
Copy link

@dr-dimitru done

@dr-dimitru
Copy link
Member Author

Hi @renatomattos2912 ,

In v1.7.3 various fixes about base64 uploads. Could you test it on your end?

@renatomattos2912
Copy link

Hi @dr-dimitru of course, i will try this week and soon i tell you. Thanks

@ouya99
Copy link

ouya99 commented Sep 19, 2016

+1

@luixal
Copy link

luixal commented Dec 28, 2016

Hi!,

I've seen that insert function is only available con client side, what would be the best way to store a b64 file in server?

I'm trying to make this work with the nimble:restivus package for uploading files through an HTTP POST/PUT.

Thanks!

@dr-dimitru
Copy link
Member Author

Hello @luixal ,

On server the is various methods like write and load

For upload via POST check out this example

@luixal
Copy link

luixal commented Dec 29, 2016

Yep, I finally make it work using the write function, works like a charm :)

Another thing (unrelated to this issue): in order to show images and download link, I have to use the template helper {{fileURL fileRef 'thumb'}} if I try getting the link field it's always null. Any ideas on how to get the URL without using that helper?

Thanks!

@luixal
Copy link

luixal commented Dec 29, 2016

Hmmm... there's another problem I'm having. According to the wiki, the write function returns the collection itself:

Returns {Files} - Current FilesCollection instance

Wouldn't it be better if it returns the _id of the saved file as other collections do?

If I do something like:

let result = Images.write(
  new Buffer(base64Data, 'base64'),
  {
    fileName: 'uploaded_' + (new Date()).getTime() + '.png',
    type: 'image/png'
    }
  );

would it block until result gets a value?

@dr-dimitru
Copy link
Member Author

@luixal document from MongoDB returned in callback

if I try getting the link field it's always null

How do you call it? Need to see your code

@luixal
Copy link

luixal commented Dec 31, 2016

I finally managed to make the link() function work. I guess I was trying to call it on the object, not the FileCursor.

As for the result of the write function, is there any way to get the _id or the full object of the last written file?

With all collections I usually call them like this:

let inserted = MyCollection.insert(object);

This allows me to get the inserted object and also block the function until I get a result (really useful in methods and API functions).

Any idea on how to make this work that way?

Thanks!

@dr-dimitru
Copy link
Member Author

Hi @luixal ,

write method is asynchronous, only way to work via callback or wrap it into wrapAsync, like:

Images = new FilesCollection({/*...*/});

Images.writeSync = Meteor.wrapAsync(Images.write);

That's it :)

@luixal
Copy link

luixal commented Jan 3, 2017

Hi there!

That's how I'm using it, was just wondering if it wouldn't be useful to make it work like regular collections :)

let resultId = MyCollection.insert({...}) // <--- sync
MyCollection.insert(...); // <--- async and allows you to pass a callback or not

Thanks!

@dr-dimitru
Copy link
Member Author

@luixal it will cost efficiency, as it will be blocking IO. Working with FS is different than DB.

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

4 participants