fix: Assumption that url passed to storeFromUrl will send content-length header
This commit is contained in:
@@ -131,13 +131,12 @@ export default abstract class BaseStorage {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let buffer, contentLength, contentType;
|
let buffer, contentType;
|
||||||
const match = url.match(/data:(.*);base64,(.*)/);
|
const match = url.match(/data:(.*);base64,(.*)/);
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
contentType = match[1];
|
contentType = match[1];
|
||||||
buffer = Buffer.from(match[2], "base64");
|
buffer = Buffer.from(match[2], "base64");
|
||||||
contentLength = buffer.byteLength;
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
@@ -155,7 +154,6 @@ export default abstract class BaseStorage {
|
|||||||
|
|
||||||
contentType =
|
contentType =
|
||||||
res.headers.get("content-type") ?? "application/octet-stream";
|
res.headers.get("content-type") ?? "application/octet-stream";
|
||||||
contentLength = parseInt(res.headers.get("content-length") ?? "0", 10);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.error("Error fetching URL to upload", err, {
|
Logger.error("Error fetching URL to upload", err, {
|
||||||
url,
|
url,
|
||||||
@@ -166,6 +164,7 @@ export default abstract class BaseStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const contentLength = buffer.byteLength;
|
||||||
if (contentLength === 0) {
|
if (contentLength === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -173,7 +172,6 @@ export default abstract class BaseStorage {
|
|||||||
try {
|
try {
|
||||||
const result = await this.store({
|
const result = await this.store({
|
||||||
body: buffer,
|
body: buffer,
|
||||||
contentLength,
|
|
||||||
contentType,
|
contentType,
|
||||||
key,
|
key,
|
||||||
acl,
|
acl,
|
||||||
@@ -182,8 +180,8 @@ export default abstract class BaseStorage {
|
|||||||
return result
|
return result
|
||||||
? {
|
? {
|
||||||
url: result,
|
url: result,
|
||||||
contentType,
|
|
||||||
contentLength,
|
contentLength,
|
||||||
|
contentType,
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user