Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Upload fails when using WebDav as file storage #26711

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/meteor/app/file-upload/ufs/Webdav/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class WebdavStore extends UploadFS.Store {
.then((data) => {
callback && callback(null, data);
})
.catch(SystemLogger.error);
.catch((...args) => SystemLogger.error(...args));
};

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ export class WebdavStore extends UploadFS.Store {
*/
this.getWriteStream = function (fileId, file) {
const writeStream = new stream.PassThrough();
const webdavStream = client.createWriteStream(this.getPath(file));
const webdavStream = client.createWriteStream(this.getPath(file), file.size || 0);

// TODO remove timeout when UploadFS bug resolved
const newListenerCallback = (event, listener) => {
Expand Down
20 changes: 18 additions & 2 deletions apps/meteor/app/webdav/server/lib/webdavClientAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import stream from 'stream';
import type { Readable, Writable } from 'stream';

import type { WebDAVClient, FileStat, ResponseDataDetailed, WebDAVClientOptions } from 'webdav';
Expand Down Expand Up @@ -69,7 +70,22 @@ export class WebdavClientAdapter {
return this._client.createReadStream(path, options);
}

createWriteStream(path: string): Writable {
return this._client.createWriteStream(path);
createWriteStream(path: string, fileSize: number): Writable {
const ws = new stream.PassThrough();

this._client
.customRequest(path, {
method: 'PUT',
headers: {
...(fileSize ? { 'Content-Length': String(fileSize) } : {}),
},
data: ws,
maxRedirects: 0,
})
.catch((err) => {
ws.emit('error', err);
});

return ws;
}
}
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
"use-sync-external-store": "^1.2.0",
"uuid": "^8.3.2",
"vm2": "^3.9.10",
"webdav": "^4.10.0",
"webdav": "^4.11.0",
"xml-crypto": "^2.1.4",
"xml-encryption": "2.0.0",
"xml2js": "0.4.23",
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6354,7 +6354,7 @@ __metadata:
use-sync-external-store: ^1.2.0
uuid: ^8.3.2
vm2: ^3.9.10
webdav: ^4.10.0
webdav: ^4.11.0
webpack: ^4.46.0
xml-crypto: ^2.1.4
xml-encryption: 2.0.0
Expand Down Expand Up @@ -25943,7 +25943,7 @@ __metadata:
languageName: node
linkType: hard

"minimatch@npm:^5.0.1":
"minimatch@npm:^5.1.0":
version: 5.1.0
resolution: "minimatch@npm:5.1.0"
dependencies:
Expand Down Expand Up @@ -36270,9 +36270,9 @@ __metadata:
languageName: node
linkType: hard

"webdav@npm:^4.10.0":
version: 4.10.0
resolution: "webdav@npm:4.10.0"
"webdav@npm:^4.11.0":
version: 4.11.0
resolution: "webdav@npm:4.11.0"
dependencies:
axios: ^0.27.2
base-64: ^1.0.0
Expand All @@ -36282,12 +36282,12 @@ __metadata:
hot-patcher: ^0.5.0
layerr: ^0.1.2
md5: ^2.3.0
minimatch: ^5.0.1
minimatch: ^5.1.0
nested-property: ^4.0.0
path-posix: ^1.0.0
url-join: ^4.0.1
url-parse: ^1.5.10
checksum: 0cfea9c233cfb8c490b6f6be01cb789f20fd01dbfe0ebc8f89057000390117a7cdbd55501c5fc248f54f2393d529cc60a058bf982d96e7e2507a7c99528444ab
checksum: 0a7aab0a3118deea20485d3c417fda40e71c3930b866a92cfff5dedce4a25c0fbed0cd083bf14ac5a4ee7cab55136265d5011b2601cbb2a1b359da551910ec97
languageName: node
linkType: hard

Expand Down