Skip to content

Commit

Permalink
Add filename to uploadEnd event
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosnils committed Oct 31, 2020
1 parent 7357473 commit 0ce5360
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pwd-sdk",
"version": "0.0.6",
"version": "0.0.7",
"description": "PWD sdk",
"main": "dist/index.js",
"mainReact": "react/index.js",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class PWD extends EventEmitter {
};
upload(name, opts, callback = (any) => {}) {
var self = this;
let { data, path = "", url = "" } = opts;
let { name:filename, data, path = "", url = "" } = opts;
if (data && url) {
callback(new Error(`Both data and url can't be set when uploading files`))
return
Expand All @@ -322,7 +322,7 @@ class PWD extends EventEmitter {
},
function (response) {
let err = response.status == 200 ? undefined : new Error();
self.emitEvent("uploadEnd", [err]);
self.emitEvent("uploadEnd", [err, path + "/" + filename , self.instances[name]]);
callback(err);
}
);
Expand Down
11 changes: 6 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,22 @@ export function registerInputHandlers(termName, instance) {
var url = a.getAttribute("data-source-url") || undefined;
var dataSrc = a.getAttribute("data-upload-src") || undefined;

let data;
let data, name;
if (dataSrc) {
let parts = dataSrc.split(":");
let [dname, bdata] = dataSrc.split(":");
name = dname;
let formData = new FormData();

// Decode base64 to ascii
let binData = atob(parts[1])
let binData = atob(bdata);
var blob = new Blob([binData], { type: "text/plain"});
formData.append("file", blob, parts[0]);
formData.append("file", blob, name);
data = formData;
}

a.addEventListener("click", function () {
// TODO decide callback action
self.upload(instance.name, {path, url, data});
self.upload(instance.name, {path, url, data, name});
});
});
// Attach file uploads
Expand Down

0 comments on commit 0ce5360

Please sign in to comment.