forge 大文件上传, 返回504。
问题描述
forge-node-apiuploadchunk()
返回504
问题出现的环境背景及自己尝试过哪些方法
我试图通过 在aws s3上获取一个(380M)已经存在的obj模型,然后使用forge-node-api上传到forge s3。 开始我使用ObjectsApi().uploadObject()
这个方式进行上传。
RangeError: Array buffer allocation failed
查看文档发现Note that for objects larger than 100 MB we recommend using the[PUT buckets/:bucketKey/objects/:objectName/resumable]endpoint.
对应到forge-node-api中
/**
* This endpoint allows resumable uploads for large files in chunks.
*/
uploadChunk(
bucketKey: string,
objectName: string,
contentLength: number,
contentRange: string,
sessionId: string,
body: string | Buffer,
opts: { contentDisposition?: string; ifMatch?: string },
oauth2Client: AuthClient,
credentials: AuthToken,
): Promise<ApiResponse>;
相关代码
async function uploadToAutdeskForgeChunk(key,contentLength,buffer) {
console.log('start upload autodesk forge chunk ');
const bucketKey = "7tzrrgdkveypaae9rm7ba6xm9sujgplb-testbuckey123";
let chunkSize = 5*1024*1024;
let chunkNumber = buffer.length / chunkSize;
chunkNumber = Math.round(0.5 + chunkNumber);
let promises = [];
let token = await getInternalToken();
for(let i = 0; i < chunkNumber; i++) {
let start = i * chunkSize;
let end = Math.min(buffer.length, (i + 1)*chunkSize) - 1;
let range = "bytes " + start + "-" + end + "/" + buffer.length;
let chunklength = end - start + 1;
let sessionID = "64546463132131" + i; //测试用
console.log(range);
let chunk = buffer.slice(start, end);
console.log(chunk.length)
// promises.push(new ObjectsApi().uploadChunk(bucketKey, key, chunklength, range, sessionID, buffer.slice(start, end), {}, getClient(), token ))
new ObjectsApi().uploadChunk(bucketKey, key, chunklength, range, sessionID, chunk, {}, getClient(), token ).then( (res) => {
console.log(res);
}).catch( (err) => {console.log(err)})
}
// return Promise.all(promises)
}
实际看到的错误信息又是什么?
{ statusCode: 504, statusMessage: 'GATEWAY_TIMEOUT', statusBody: '' }
sometime:
Error: ESOCKETTIMEDOUT
at ClientRequest.<anonymous> (/home/ec2-user/forge_demo/node_modules/request/request.js:816:19)
at Object.onceWrapper (events.js:421:28)
at ClientRequest.emit (events.js:315:20)
at ClientRequest.EventEmitter.emit (domain.js:485:12)
at TLSSocket.emitRequestTimeout (_http_client.js:721:9)
at Object.onceWrapper (events.js:421:28)
at TLSSocket.emit (events.js:327:22)
at TLSSocket.EventEmitter.emit (domain.js:485:12)
at TLSSocket.Socket._onTimeout (net.js:481:8)
at listOnTimeout (internal/timers.js:549:17) {
code: 'ESOCKETTIMEDOUT',
connect: false
}
从status code来看应该是服务端出问题了,但是不太确定,到底是哪出的问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论