Rovak / InlineAttachment

Easily paste and upload files/images in plain textareas
http://git.razko.nl/InlineAttachment
MIT License
619 stars 77 forks source link

Saving with attached file name #23

Closed afzal-lakdawala closed 9 years ago

afzal-lakdawala commented 10 years ago

Which method should to use for same filename output and stored for e.g filename is "test.jpg" but after uploading it's change to "image-1388234246756.jpg". How should i resolved this.

Rovak commented 10 years ago

Hi Afzal, it depends on the way you are copying the image. The library supports both drag&drop and copy+paste in a textarea. When using dragdrop the filename is available, but when copy pasting the image then the filename is not available because then its just a blob of data.

Because the filename is not always available (and irrelevant if only used to link to an image) i decided to use a "random" number which is being done at this line

This cannot be resolved in the current version of the library, i suggest to add a new method which is being fired when a filename is being generated, something like:

/**
 * @param {String} filename Filename when drag&drop, null when copy+paste
 */
onGenerateFilename: function(filename) {
  if(!filename) {
    return 'random-filename.jpg'
  }
  return filename;
}
afzal-lakdawala commented 10 years ago

Thanks for reply. But whatever i had drag so it should take same exact name.

afzal-lakdawala commented 10 years ago

Also this onGenerateFilename not working.

Rovak commented 10 years ago

I agree that the filename should be used when the name is available, i will keep this issue open as a todo to add this functionality in the future.

The onGenerateFilename method is not available yet and was merely a suggestion for a way to fix the issue with a new PR.

afzal-lakdawala commented 10 years ago

Okay... I will spend some time onto this and send you PR for this issue.

Rovak commented 9 years ago

Fixed in v2