Rovak / InlineAttachment

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

downloadFieldName #19

Closed newtonianb closed 10 years ago

newtonianb commented 10 years ago

When I upload a file the server I'm dealing with returns a json in the format, how can I tell it where the URL from this response is? It looks downloadFileName looks to be the one but how exactly?

files: [{name:8001020224.png, size:34093, type:image/jpeg,…}]
0: {name:8001020224.png, size:34093, type:image/jpeg,…}
deleteType: "DELETE"
deleteUrl: "?file=8001020224.png"
name: "8001020224.png"
size: 34093
type: "image/jpeg"
url: "http://localhost/1387896081/8001020224.png"
Rovak commented 10 years ago

assuming the response is in a valid JSON format

{
    "files": [{name:8001020224.png, size:34093, type:image/jpeg,…}],
    "0": {name:8001020224.png, size:34093, type:image/jpeg,…},
    "deleteType": "DELETE",
    "deleteUrl": "?file=8001020224.png",
    "name": "8001020224.png",
    "size": 34093,
    "type": "image/jpeg",
    "url": "http://localhost/1387896081/8001020224.png"
}

then the downloadFieldName configuration would be name.

newtonianb commented 10 years ago

Thanks Rovak, sorry It wasn't clear from the console copy paste I did. It's returning an array so 'name' is from index 0 of this array. It's a library I'm using so now I have to either change this library or the server library.

I'm seeing it's doing this filename = data[settings.downloadFieldName];

Rovak commented 10 years ago

I've just submitted a patch which can be used to manually replace the filename, see #21

onUploadedFile: function(data) {
  this.replacePendingFilename(data.files[0].name);
}

I haven't tested it yet, and i'm not sure if this refers to the proper scope, but would this fix the issue?

Rovak commented 10 years ago

@newtonianb, could you update this issue if this fixed the issue or any thoughts on the suggested solution?

newtonianb commented 10 years ago

Thank You!