Uppy: Rename image before upload to destination.

Created on 14 Apr 2020  路  1Comment  路  Source: transloadit/uppy

I've tried to rename image before its uploads to destination but no luck to get it done.

I've tried below code in onBeforeFileAdded and onBeforeUpload methods but no change in output.

        let date = Date.now();
        let newObj = {};
        Object.keys(files).forEach(fileId => {
          console.log("fileId ", fileId);
          let newId = date + '-' + fileId;
          newObj[fileId] = { ...files[fileId] }; // replicate object
          newObj[fileId].name = newId; // update data
          let obz = { ...newObj[fileId].meta };
          obz.clientFileNameToMap = newId; // update inner object
          newObj[fileId].meta = obz; // update inner object
        });
        return newObj;

Maybe I'm doing it in the wrong way. Any help would be grateful.

Not Accepted Triage

Most helpful comment

your onBeforeFileAdded should look something like this:

onBeforeFileAdded: function (currentFile, files) {
      currentFile.name = 'my new file name'
      return currentFile;
  }

>All comments

your onBeforeFileAdded should look something like this:

onBeforeFileAdded: function (currentFile, files) {
      currentFile.name = 'my new file name'
      return currentFile;
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

agreene-coursera picture agreene-coursera  路  4Comments

oyeanuj picture oyeanuj  路  3Comments

anushkamds picture anushkamds  路  3Comments

skunkwerk picture skunkwerk  路  3Comments

quetzyg picture quetzyg  路  3Comments