适配最新的文件上传接口
This commit is contained in:
parent
5a1dba7a8f
commit
a2102bdb5e
|
@ -347,14 +347,11 @@
|
|||
:disable="uploader_loading"
|
||||
:url="getUrl"
|
||||
multiple
|
||||
method="post"
|
||||
:headers="generatorFileUploadHeaders"
|
||||
method="POST"
|
||||
:label="$t('select file') + ':'"
|
||||
:accept="uploader_accept"
|
||||
@start="onStartUpload"
|
||||
@uploaded="onUploaded"
|
||||
@failed="onFailed"
|
||||
@added="/*onFileAdded*/ null"
|
||||
@finish="onFailed"
|
||||
>
|
||||
</q-uploader>
|
||||
<q-space />
|
||||
|
@ -882,21 +879,6 @@ export default defineComponent({
|
|||
resolve = _resolve;
|
||||
});
|
||||
},
|
||||
generatorFileUploadHeaders(files: File[]) {
|
||||
if (files.length > 0) {
|
||||
return [
|
||||
{
|
||||
name: HttpProtocol.kHeaderXProductName,
|
||||
value: HttpProtocol.getProductName($store),
|
||||
},
|
||||
{
|
||||
name: HttpProtocol.kHeaderXFileLength,
|
||||
value: files[0].size,
|
||||
},
|
||||
];
|
||||
}
|
||||
return [];
|
||||
},
|
||||
resetData() {
|
||||
loading.value = false;
|
||||
uploading.value = false;
|
||||
|
@ -1068,8 +1050,8 @@ export default defineComponent({
|
|||
getUrl(file: File[]) {
|
||||
let url = GlobalData.getInstance().createCurrentRequestUrl();
|
||||
if (url) {
|
||||
url.pathname = HttpProtocol.RequestUploadFile;
|
||||
url.searchParams.append("type", HttpProtocol.HttpUploadTypeNormal);
|
||||
url.pathname = "/upload_media_file"; //HttpProtocol.RequestUploadFile;
|
||||
// url.searchParams.append("type", HttpProtocol.HttpUploadTypeNormal);
|
||||
url.searchParams.append("base_dir", path.value);
|
||||
return url.toString();
|
||||
}
|
||||
|
@ -1078,89 +1060,6 @@ export default defineComponent({
|
|||
onStartUpload() {
|
||||
loading.value = true;
|
||||
},
|
||||
async onFileAdded(files: File[] | File) {
|
||||
setTimeout(async () => {
|
||||
const onError = async (file: File | null) => {
|
||||
await nextTick(() => {});
|
||||
uploader.value.reset();
|
||||
|
||||
$q.notify({
|
||||
color: "negative",
|
||||
icon: "warning",
|
||||
message: $t.t("load file error") + "!",
|
||||
position: "top",
|
||||
timeout: 3000,
|
||||
});
|
||||
};
|
||||
|
||||
let file: File | null = null;
|
||||
|
||||
try {
|
||||
if (Array.isArray(files)) {
|
||||
if (files.length > 0) {
|
||||
file = files[0];
|
||||
}
|
||||
} else {
|
||||
file = files;
|
||||
}
|
||||
if (file) {
|
||||
const file_name = file.name;
|
||||
const blob = file.slice(0, 1024 * 1024 * 1); // 1 MB
|
||||
uploader_loading.value = true;
|
||||
|
||||
try {
|
||||
let url = GlobalData.getInstance().createCurrentRequestUrl();
|
||||
if (url) {
|
||||
url.pathname = HttpProtocol.RequestPathCheckFileSupport;
|
||||
|
||||
// if (FileSuffixHelper.isVideoPath(file_name)) {
|
||||
|
||||
// }
|
||||
const data = new FormData();
|
||||
data.append(
|
||||
"file",
|
||||
new File([blob], file_name, {
|
||||
lastModified: file.lastModified,
|
||||
})
|
||||
);
|
||||
const response = await api.post(url.toString(), data, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
});
|
||||
if (response && response.data && response.data.is_support) {
|
||||
} else {
|
||||
onError(file);
|
||||
}
|
||||
} else {
|
||||
throw "";
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
onError(file);
|
||||
}
|
||||
uploader_loading.value = false;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
onError(file);
|
||||
}
|
||||
}, 1);
|
||||
},
|
||||
onUploaded(info: any) {
|
||||
uploading.value = false;
|
||||
uploader.value.reset();
|
||||
refresh_file_list();
|
||||
|
||||
$q.notify({
|
||||
type: "positive",
|
||||
message: $t.t("file upload") + $t.t("success") + "!",
|
||||
position: "top",
|
||||
timeout: 1500,
|
||||
});
|
||||
loading.value = false;
|
||||
},
|
||||
async onFailed(info: any) {
|
||||
let file_list: any = await _request_list_files(path.value);
|
||||
setTimeout(() => {
|
||||
|
@ -1174,7 +1073,6 @@ export default defineComponent({
|
|||
loading.value = false;
|
||||
}
|
||||
}, 500);
|
||||
|
||||
},
|
||||
copyFile(file: FileEntity) {
|
||||
if (file) {
|
||||
|
|
Loading…
Reference in New Issue