-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIO 7239: support for AWS S3 Multipart Upload (#5356)
* add multipart checkbox to file component editForm * refactor xhr in storage and add support for s3 multipart uploads * refactor to async/await * add support for midstream cancel * minor * refactor withRetries into util * begin tests * minor
- Loading branch information
1 parent
a381c68
commit 19b1e4f
Showing
13 changed files
with
634 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
import XHR from './xhr'; | ||
const azure = (formio) => ({ | ||
uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback) { | ||
return XHR.upload(formio, 'azure', (xhr, response) => { | ||
xhr.openAndSetHeaders('PUT', response.url); | ||
xhr.setRequestHeader('Content-Type', file.type); | ||
xhr.setRequestHeader('x-ms-blob-type', 'BlockBlob'); | ||
return file; | ||
}, file, fileName, dir, progressCallback, groupPermissions, groupId, abortCallback).then(() => { | ||
return { | ||
storage: 'azure', | ||
name: XHR.path([dir, fileName]), | ||
size: file.size, | ||
type: file.type, | ||
groupPermissions, | ||
groupId, | ||
}; | ||
}); | ||
}, | ||
downloadFile(file) { | ||
return formio.makeRequest('file', `${formio.formUrl}/storage/azure?name=${XHR.trim(file.name)}`, 'GET'); | ||
} | ||
}); | ||
function azure(formio) { | ||
return { | ||
uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback) { | ||
return XHR.upload(formio, 'azure', (xhr, response) => { | ||
xhr.openAndSetHeaders('PUT', response.url); | ||
xhr.setRequestHeader('Content-Type', file.type); | ||
xhr.setRequestHeader('x-ms-blob-type', 'BlockBlob'); | ||
return file; | ||
}, file, fileName, dir, progressCallback, groupPermissions, groupId, abortCallback).then(() => { | ||
return { | ||
storage: 'azure', | ||
name: XHR.path([dir, fileName]), | ||
size: file.size, | ||
type: file.type, | ||
groupPermissions, | ||
groupId, | ||
}; | ||
}); | ||
}, | ||
downloadFile(file) { | ||
return formio.makeRequest('file', `${formio.formUrl}/storage/azure?name=${XHR.trim(file.name)}`, 'GET'); | ||
} | ||
}; | ||
} | ||
|
||
azure.title = 'Azure File Services'; | ||
export default azure; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
const base64 = () => ({ | ||
title: 'Base64', | ||
name: 'base64', | ||
uploadFile(file, fileName) { | ||
const reader = new FileReader(); | ||
function base64() { | ||
return { | ||
title: 'Base64', | ||
name: 'base64', | ||
uploadFile(file, fileName) { | ||
const reader = new FileReader(); | ||
|
||
return new Promise((resolve, reject) => { | ||
reader.onload = (event) => { | ||
const url = event.target.result; | ||
resolve({ | ||
storage: 'base64', | ||
name: fileName, | ||
url: url, | ||
size: file.size, | ||
type: file.type, | ||
}); | ||
}; | ||
return new Promise((resolve, reject) => { | ||
reader.onload = (event) => { | ||
const url = event.target.result; | ||
resolve({ | ||
storage: 'base64', | ||
name: fileName, | ||
url: url, | ||
size: file.size, | ||
type: file.type, | ||
}); | ||
}; | ||
|
||
reader.onerror = () => { | ||
return reject(this); | ||
}; | ||
reader.onerror = () => { | ||
return reject(this); | ||
}; | ||
|
||
reader.readAsDataURL(file); | ||
}); | ||
}, | ||
downloadFile(file) { | ||
// Return the original as there is nothing to do. | ||
return Promise.resolve(file); | ||
} | ||
}); | ||
reader.readAsDataURL(file); | ||
}); | ||
}, | ||
downloadFile(file) { | ||
// Return the original as there is nothing to do. | ||
return Promise.resolve(file); | ||
} | ||
}; | ||
} | ||
|
||
base64.title = 'Base64'; | ||
export default base64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,67 @@ | ||
import { setXhrHeaders } from './xhr'; | ||
const dropbox = (formio) => ({ | ||
uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback) { | ||
return new Promise(((resolve, reject) => { | ||
// Send the file with data. | ||
const xhr = new XMLHttpRequest(); | ||
function dropbox(formio) { | ||
return { | ||
uploadFile(file, fileName, dir, progressCallback, url, options, fileKey, groupPermissions, groupId, abortCallback) { | ||
return new Promise(((resolve, reject) => { | ||
// Send the file with data. | ||
const xhr = new XMLHttpRequest(); | ||
|
||
if (typeof progressCallback === 'function') { | ||
xhr.upload.onprogress = progressCallback; | ||
} | ||
if (typeof progressCallback === 'function') { | ||
xhr.upload.onprogress = progressCallback; | ||
} | ||
|
||
if (typeof abortCallback === 'function') { | ||
abortCallback(() => xhr.abort()); | ||
} | ||
if (typeof abortCallback === 'function') { | ||
abortCallback(() => xhr.abort()); | ||
} | ||
|
||
const fd = new FormData(); | ||
fd.append('name', fileName); | ||
fd.append('dir', dir); | ||
fd.append('file', file); | ||
const fd = new FormData(); | ||
fd.append('name', fileName); | ||
fd.append('dir', dir); | ||
fd.append('file', file); | ||
|
||
// Fire on network error. | ||
xhr.onerror = (err) => { | ||
err.networkError = true; | ||
reject(err); | ||
}; | ||
// Fire on network error. | ||
xhr.onerror = (err) => { | ||
err.networkError = true; | ||
reject(err); | ||
}; | ||
|
||
xhr.onload = () => { | ||
if (xhr.status >= 200 && xhr.status < 300) { | ||
const response = JSON.parse(xhr.response); | ||
response.storage = 'dropbox'; | ||
response.size = file.size; | ||
response.type = file.type; | ||
response.groupId = groupId; | ||
response.groupPermissions = groupPermissions; | ||
response.url = response.path_lower; | ||
resolve(response); | ||
} | ||
else { | ||
reject(xhr.response || 'Unable to upload file'); | ||
} | ||
}; | ||
xhr.onload = () => { | ||
if (xhr.status >= 200 && xhr.status < 300) { | ||
const response = JSON.parse(xhr.response); | ||
response.storage = 'dropbox'; | ||
response.size = file.size; | ||
response.type = file.type; | ||
response.groupId = groupId; | ||
response.groupPermissions = groupPermissions; | ||
response.url = response.path_lower; | ||
resolve(response); | ||
} | ||
else { | ||
reject(xhr.response || 'Unable to upload file'); | ||
} | ||
}; | ||
|
||
xhr.onabort = reject; | ||
xhr.onabort = reject; | ||
|
||
xhr.open('POST', `${formio.formUrl}/storage/dropbox`); | ||
xhr.open('POST', `${formio.formUrl}/storage/dropbox`); | ||
|
||
setXhrHeaders(formio, xhr); | ||
setXhrHeaders(formio, xhr); | ||
|
||
const token = formio.getToken(); | ||
if (token) { | ||
xhr.setRequestHeader('x-jwt-token', token); | ||
} | ||
xhr.send(fd); | ||
})); | ||
}, | ||
downloadFile(file) { | ||
const token = formio.getToken(); | ||
if (token) { | ||
xhr.setRequestHeader('x-jwt-token', token); | ||
} | ||
xhr.send(fd); | ||
})); | ||
}, | ||
downloadFile(file) { | ||
const token = formio.getToken(); | ||
file.url = | ||
`${formio.formUrl}/storage/dropbox?path_lower=${file.path_lower}${token ? `&x-jwt-token=${token}` : ''}`; | ||
return Promise.resolve(file); | ||
} | ||
}); | ||
file.url = | ||
`${formio.formUrl}/storage/dropbox?path_lower=${file.path_lower}${token ? `&x-jwt-token=${token}` : ''}`; | ||
return Promise.resolve(file); | ||
} | ||
}; | ||
} | ||
|
||
dropbox.title = 'Dropbox'; | ||
export default dropbox; |
Oops, something went wrong.