mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
use remoteStorage.uploadFile
method
This commit is contained in:
parent
f655eea613
commit
edd6b2534b
@ -9,54 +9,24 @@ export default (props) => {
|
|||||||
const handleUpload = async (req) => {
|
const handleUpload = async (req) => {
|
||||||
setUploading(true)
|
setUploading(true)
|
||||||
|
|
||||||
const formData = new FormData()
|
const response = await app.cores.remoteStorage.uploadFile(req.file).catch((err) => {
|
||||||
|
app.notification.new({
|
||||||
formData.append("files", req.file)
|
message: "Could not upload file",
|
||||||
|
description: err.message
|
||||||
const response = await window.app.cores.api.customRequest({
|
}, {
|
||||||
url: "/files/upload",
|
type: "error"
|
||||||
method: "POST",
|
})
|
||||||
data: formData
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
app.message.error(error.respose.data.message)
|
|
||||||
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response) {
|
if (typeof props.ctx?.onUpdateItem === "function") {
|
||||||
// check failed uploads
|
props.ctx.onUpdateItem(response.url)
|
||||||
if (response.data.failed.length > 0) {
|
}
|
||||||
app.notification.new({
|
|
||||||
message: "Could not upload files",
|
|
||||||
description: () => {
|
|
||||||
return response.data.failed.map((fail) => {
|
|
||||||
return <div
|
|
||||||
style={{
|
|
||||||
marginBottom: 5
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<b>[{fail.fileName}]</b> - {fail.error}
|
|
||||||
</div>
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
type: "error"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.data.files.length > 0) {
|
if (typeof props.onUploadDone === "function") {
|
||||||
if (typeof props.ctx?.onUpdateItem === "function") {
|
if (props.multiple) {
|
||||||
props.ctx.onUpdateItem(response.data.files[0].url)
|
await props.onUploadDone(response)
|
||||||
}
|
} else {
|
||||||
|
await props.onUploadDone(response)
|
||||||
if (typeof props.onUploadDone === "function") {
|
|
||||||
if (props.multiple) {
|
|
||||||
await props.onUploadDone(response.data.files)
|
|
||||||
} else {
|
|
||||||
await props.onUploadDone(response.data.files[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user