zefoy / ngx-dropzone-wrapper

Angular wrapper library for Dropzone
MIT License
174 stars 51 forks source link

sending raw file data #87

Closed tatsujb closed 6 years ago

tatsujb commented 6 years ago

apparently this is possible via this fix : https://github.com/enyo/dropzone/issues/590#issuecomment-51498225

I don't get how I would implement this in this package, though?

sconix commented 6 years ago

I don't see anything special in there. Everything you can do with Dropzone you can do with this wrapper and almost exactly the same way. All this wrapper does is initializes dropzone according to the config and monitors for changes in the config. So without more specific question I can not help you. If you are just asking how to use this wrapper then other forums might be better since not so many users monitor these issue.

tatsujb commented 6 years ago

thanks,

please forgive my noobyness

header and method I get where I could put, but will

init: function() {
    const dz = this,
          action = dz.element.action,
          sas = dz.element.dataset.sas;

    dz.on("processing", (file) => {
      dz.options.headers["Content-Type"] = file.type;
      dz.options.url = `${action}/${settings.country}/${settings.language}/${file.name}?${sas}`;
})

work if I also put it in DEFAULT_DROPZONE_CONFIG ?

sconix commented 6 years ago

All dropzone events are usable as outputs so no need to use the 'on' method. When you need to modify the dropzone instance in the event handler you need to get the the dropzone instance which can be get using dropzone() function through the directiveRef (see README / example app). Then you can update the options in the dropzone instance normally.

tatsujb commented 6 years ago

Thanks for having already taken some time 👍

something like this? :

const DEFAULT_DROPZONE_CONFIG: DropzoneConfigInterface = {
  url: 'http://localhost:8080/purchaseorders/import',
  maxFilesize: 5000,
  method: "PUT",
  headers: {"x-ms-blob-type": "BlockBlob"},
  init: function() {
    this.dropzone().options.headers["Content-Type"] = file.type;
    this.dropzone().options.url = `${this.dropzone().dz.element.action}/${settings.language}/${settings.language}/${file.name}?${this.dropzone().element.dataset.sas}`;
  }
};

I still don't understand in that code what I should set as file.type settings.country and settings.country.

would this.dropzone().type work for file.type, for example?

navigator.language for settings.language and hard coded "US" or "FR" for settings.language?

many thanks

sconix commented 6 years ago

You might need to study the basics of Angular first before trying to do something as complex. Hopefully somebody has more time to give you ready examples.

tatsujb commented 6 years ago

believe me I'd love to have the time but my boss won't hear it.

the "basics of Angular" according to you aren't what's universally understood when people use those words in conjunction. I've gotten, by now, the memo that you're good.

I'm new to angular but I'm a bit beyond what I define as the "basics".

being able to upturn the entrails of any angular npm plugin I may come across with ease isn't exactly "basic".

tatsujb commented 6 years ago

for future reference (others who might have the same question &/or level as me) I found this stack overflow : https://stackoverflow.com/questions/38781909/webkitformboundary-included-in-file-payload-on-direct-upload-to-s3/39091650#39091650

and with slight modifications I managed to get it working :

const DEFAULT_DROPZONE_CONFIG: DropzoneConfigInterface = {
  url: '/purchaseorders/import',
  maxFilesize: 5000,
  method: "POST",
  headers: {"Content-Type": "text/csv; charset=windows-1252"},
  init: function() {
    const dz = this;
    dz.on("sending", function(file, xhr, formData) {
      const _send = xhr.send;
      xhr.send = function() {
        _send.call(xhr, file);
      }
    });
  }
};
sconix commented 6 years ago

Well this is a profession where you learn every day :) I just try to re-direct the usage support questions more towards stackoverflow since it really is better place than git issues for finding and getting help. And I can only offer solutions that are more Angular based (since I am not that familiar with dropzone) so nice to see that there was also "pure" dropzone way to do it.