mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-27 10:52:41 +03:00
upload: lifts file upload restrictions, still needs testing
This commit is contained in:
parent
b70b01641e
commit
59f64a2888
@ -5,6 +5,7 @@ import * as Utilities from "~/node_common/utilities";
|
|||||||
import FS from "fs-extra";
|
import FS from "fs-extra";
|
||||||
import FORM from "formidable";
|
import FORM from "formidable";
|
||||||
|
|
||||||
|
// TODO(jim): Ideally we never keep the file locally.
|
||||||
export const formMultipart = (req, res, { user }) =>
|
export const formMultipart = (req, res, { user }) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const f = new FORM.IncomingForm();
|
const f = new FORM.IncomingForm();
|
||||||
@ -19,11 +20,9 @@ export const formMultipart = (req, res, { user }) =>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(files);
|
|
||||||
|
|
||||||
if (!files.data) {
|
if (!files.data) {
|
||||||
return reject({
|
return reject({
|
||||||
decorator: "SERVER_UPLOAD_ERROR",
|
decorator: "SERVER_UPLOAD_ERROR_CHECK_FORM_TYPE",
|
||||||
error: true,
|
error: true,
|
||||||
message: files,
|
message: files,
|
||||||
});
|
});
|
||||||
@ -33,12 +32,19 @@ export const formMultipart = (req, res, { user }) =>
|
|||||||
const localPath = `./${path}`;
|
const localPath = `./${path}`;
|
||||||
const data = LibraryManager.createLocalDataIncomplete(files.data);
|
const data = LibraryManager.createLocalDataIncomplete(files.data);
|
||||||
|
|
||||||
const { buckets, bucketKey, bucketName } = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api);
|
const {
|
||||||
|
buckets,
|
||||||
|
bucketKey,
|
||||||
|
bucketName,
|
||||||
|
} = await Utilities.getBucketAPIFromUserToken(user.data.tokens.api);
|
||||||
|
|
||||||
let readFile;
|
let readFile;
|
||||||
let push;
|
let push;
|
||||||
try {
|
try {
|
||||||
readFile = await FS.readFileSync(path).buffer;
|
readFile = FS.createReadStream(path, {
|
||||||
|
highWaterMark: 1024 * 1024 * 3,
|
||||||
|
});
|
||||||
|
|
||||||
push = await buckets.pushPath(bucketKey, data.name, readFile);
|
push = await buckets.pushPath(bucketKey, data.name, readFile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await FS.unlinkSync(localPath);
|
await FS.unlinkSync(localPath);
|
||||||
@ -49,7 +55,6 @@ export const formMultipart = (req, res, { user }) =>
|
|||||||
message: e,
|
message: e,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(jim): Remove the file when you're done with it.
|
// NOTE(jim): Remove the file when you're done with it.
|
||||||
await FS.unlinkSync(localPath);
|
await FS.unlinkSync(localPath);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user