Browse Source

transloadit: First working URL import

Renée Kooi 7 years ago
parent
commit
cebc0ee581
2 changed files with 13 additions and 9 deletions
  1. 5 3
      src/plugins/Transloadit/Client.js
  2. 8 6
      src/plugins/Transloadit/index.js

+ 5 - 3
src/plugins/Transloadit/Client.js

@@ -30,7 +30,7 @@ module.exports = class Client {
     Object.keys(fields).forEach((key) => {
       data.append(key, fields[key])
     })
-    data.append('tus_num_expected_upload_files', expectedFiles)
+    data.append('num_expected_upload_files', expectedFiles)
 
     return fetch(`${this.apiUrl}/assemblies`, {
       method: 'post',
@@ -49,7 +49,7 @@ module.exports = class Client {
 
   reserveFile (assembly, file) {
     const size = encodeURIComponent(file.size)
-    return fetch(`${assembly.assembly_ssl_url}/reserve_file?size=${size}`)
+    return fetch(`${assembly.assembly_ssl_url}/reserve_file?size=${size}`, { method: 'post' })
       .then((response) => response.json())
   }
 
@@ -61,7 +61,9 @@ module.exports = class Client {
     const url = encodeURIComponent(file.uploadURL)
     const filename = encodeURIComponent(file.name)
     const fieldname = 'file'
-    return fetch(`${assembly.assembly_ssl_url}/add_file?size=${size}&filename=${filename}&fieldname=${fieldname}&s3Url=${url}`)
+
+    const qs = `size=${size}&filename=${filename}&fieldname=${fieldname}&s3Url=${url}`
+    return fetch(`${assembly.assembly_ssl_url}/add_file?${qs}`, { method: 'post' })
       .then((response) => response.json())
   }
 

+ 8 - 6
src/plugins/Transloadit/index.js

@@ -153,11 +153,13 @@ module.exports = class Transloadit extends Plugin {
         const transloadit = {
           assembly: assembly.assembly_id
         }
-        return Object.assign(
-          {},
-          file,
-          { meta, tus, transloadit }
-        )
+
+        const newFile = Object.assign({}, file, { transloadit })
+        // Only configure the Tus plugin if we are uploading straight to Transloadit (the default).
+        if (!opts.importFromUploadURLs) {
+          Object.assign(newFile, { meta, tus })
+        }
+        return newFile
       }
 
       const files = Object.assign({}, this.core.state.files)
@@ -427,7 +429,7 @@ module.exports = class Transloadit extends Plugin {
     this.core.addPostProcessor(this.afterUpload)
 
     if (this.opts.importFromUploadURLs) {
-      this.core.on('file:upload-success', this.onFileUploaded)
+      this.core.on('core:upload-success', this.onFileUploaded)
     }
 
     this.updateState({