|
@@ -16,6 +16,7 @@ import { FileSystemHandle } from "./filesystem";
|
|
|
import { isValidExcalidrawData } from "./json";
|
|
|
import { restore } from "./restore";
|
|
|
import { ImportedLibraryData } from "./types";
|
|
|
+const AWS: any = require("https://pbl.cocorobo.cn/pbl-student-table/dist/js/aws-sdk-2.235.1.min.js");
|
|
|
|
|
|
const parseFileContents = async (blob: Blob | File) => {
|
|
|
let contents: string;
|
|
@@ -158,7 +159,7 @@ export const loadFromBlob = async (
|
|
|
|
|
|
return result;
|
|
|
} catch (error: any) {
|
|
|
- console.error(error.message);
|
|
|
+ window.console.error(error.message);
|
|
|
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
|
|
}
|
|
|
};
|
|
@@ -204,7 +205,7 @@ export const generateIdFromFile = async (file: File): Promise<FileId> => {
|
|
|
);
|
|
|
return bytesToHexString(new Uint8Array(hashBuffer)) as FileId;
|
|
|
} catch (error: any) {
|
|
|
- console.error(error);
|
|
|
+ window.console.error(error);
|
|
|
// length 40 to align with the HEX length of SHA-1 (which is 160 bit)
|
|
|
return nanoid(40) as FileId;
|
|
|
}
|
|
@@ -222,6 +223,53 @@ export const getDataURL = async (file: Blob | File): Promise<DataURL> => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+export const Upload_AWS = async (file: Blob | File): Promise<DataURL> => {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const credentials = {
|
|
|
+ accessKeyId: "AKIATLPEDU37QV5CHLMH",
|
|
|
+ secretAccessKey: "Q2SQw37HfolS7yeaR1Ndpy9Jl4E2YZKUuuy2muZR",
|
|
|
+ }; //秘钥形式的登录上传
|
|
|
+ AWS.config.update(credentials);
|
|
|
+ AWS.config.region = "cn-northwest-1"; //设置区域
|
|
|
+
|
|
|
+ const bucket = new AWS.S3({
|
|
|
+ params: {
|
|
|
+ Bucket: "ccrb",
|
|
|
+ },
|
|
|
+ }); //选择桶
|
|
|
+ //file.name = "";
|
|
|
+ if (file) {
|
|
|
+ const _name = file.name || "";
|
|
|
+ const params = {
|
|
|
+ Key: `${_name.split(".")[0] + new Date().getTime()}.` + `png`,
|
|
|
+ ContentType: file.type,
|
|
|
+ Body: file,
|
|
|
+ "Access-Control-Allow-Credentials": "*",
|
|
|
+ ACL: "public-read",
|
|
|
+ }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
|
|
|
+ const options = {
|
|
|
+ partSize: 2048 * 1024 * 1024,
|
|
|
+ queueSize: 2,
|
|
|
+ leavePartsOnError: true,
|
|
|
+ };
|
|
|
+ bucket
|
|
|
+ .upload(params, options)
|
|
|
+ .on("httpUploadProgress", (evt: any) => {
|
|
|
+ //这里可以写进度条
|
|
|
+ // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
|
|
|
+ })
|
|
|
+ .send((err: any, data: any) => {
|
|
|
+ if (data) {
|
|
|
+ window.console.log(data.Location);
|
|
|
+ resolve(data.Location);
|
|
|
+ } else {
|
|
|
+ reject(err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
export const dataURLToFile = (dataURL: DataURL, filename = "") => {
|
|
|
const dataIndexStart = dataURL.indexOf(",");
|
|
|
const byteString = atob(dataURL.slice(dataIndexStart + 1));
|