Skip to content

Commit 1ca36af

Browse files
committed
fix extensions upload
1 parent 04b3d2d commit 1ca36af

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

gitpod-extension/src/node/extensions/gitpod-plugin-deployer.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -350,35 +350,33 @@ export class GitpodPluginDeployer implements GitpodPluginService {
350350
}
351351
const stat = await fs.stat(FileUri.fsPath(fileUri));
352352

353-
// read file content instead of pipe stream to survive redirect
354-
const fileContent = fs.readFileSync(FileUri.fsPath(fileUri));
355-
356-
const upload = new Promise<void>((resolve, reject) => {
357-
request.put({
358-
url: targetUrl,
359-
followAllRedirects: true,
360-
followOriginalHttpMethod: true,
361-
headers: {
362-
'Content-Type': '*/*',
363-
'Content-Length': stat.size
364-
},
365-
body: fileContent
366-
}, (err, response) => {
367-
if (err) {
368-
reject(err);
369-
return;
370-
}
371-
if (response && response.statusCode !== 200) {
372-
if (response.statusCode === 400) {
373-
console.error("Bad Request: /plugin returned with code 400.", err);
353+
const upload = new Promise<void>((resolve, reject) =>
354+
fs.createReadStream(FileUri.fsPath(fileUri))
355+
.pipe(request.put({
356+
url: targetUrl,
357+
followAllRedirects: true,
358+
followOriginalHttpMethod: true,
359+
headers: {
360+
'Content-Type': '*/*',
361+
'Content-Length': stat.size
374362
}
375-
reject(new Error(response.statusMessage + " - " + response.body));
376-
return;
377-
}
378-
resolve(undefined);
379-
});
380-
});
381-
363+
}, (err, response) => {
364+
if (err) {
365+
reject(err);
366+
return;
367+
}
368+
if (response && response.statusCode !== 200) {
369+
if (response.statusCode === 400) {
370+
console.error("Bad Request: /plugin returned with code 400.", err);
371+
}
372+
reject(new Error(response.statusMessage));
373+
return;
374+
}
375+
resolve(undefined);
376+
}))
377+
.on('error', reject)
378+
.on('close', () => resolve(undefined))
379+
);
382380
try {
383381
// first try to upload ...
384382
await upload;

0 commit comments

Comments
 (0)