mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-24 18:58:57 +00:00
aws-s3: Use RequestClient.
This commit is contained in:
parent
8777591fb2
commit
cd71bc48b3
1 changed files with 14 additions and 4 deletions
|
|
@ -2,6 +2,7 @@ const resolveUrl = require('resolve-url')
|
|||
const { Plugin } = require('@uppy/core')
|
||||
const Translator = require('@uppy/utils/lib/Translator')
|
||||
const limitPromises = require('@uppy/utils/lib/limitPromises')
|
||||
const { RequestClient } = require('@uppy/companion-client')
|
||||
const XHRUpload = require('@uppy/xhr-upload')
|
||||
|
||||
function isXml (xhr) {
|
||||
|
|
@ -9,6 +10,15 @@ function isXml (xhr) {
|
|||
return typeof contentType === 'string' && contentType.toLowerCase() === 'application/xml'
|
||||
}
|
||||
|
||||
function assertServerError (res) {
|
||||
if (res && res.error) {
|
||||
const error = new Error(res.message)
|
||||
Object.assign(error, res.error)
|
||||
throw error
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
module.exports = class AwsS3 extends Plugin {
|
||||
constructor (uppy, opts) {
|
||||
super(uppy, opts)
|
||||
|
|
@ -36,6 +46,8 @@ module.exports = class AwsS3 extends Plugin {
|
|||
this.translator = new Translator({ locale: this.locale })
|
||||
this.i18n = this.translator.translate.bind(this.translator)
|
||||
|
||||
this.client = new RequestClient(uppy, opts)
|
||||
|
||||
this.prepareUpload = this.prepareUpload.bind(this)
|
||||
|
||||
if (typeof this.opts.limit === 'number' && this.opts.limit !== 0) {
|
||||
|
|
@ -52,10 +64,8 @@ module.exports = class AwsS3 extends Plugin {
|
|||
|
||||
const filename = encodeURIComponent(file.name)
|
||||
const type = encodeURIComponent(file.type)
|
||||
return fetch(`${this.opts.serverUrl}/s3/params?filename=${filename}&type=${type}`, {
|
||||
method: 'get',
|
||||
headers: { accept: 'application/json' }
|
||||
}).then((response) => response.json())
|
||||
return this.client.get(`s3/params?filename=${filename}&type=${type}`)
|
||||
.then(assertServerError)
|
||||
}
|
||||
|
||||
validateParameters (file, params) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue