-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
putFileContents() lost support for File objects in 4.x #266
Comments
@lazka Hmm, I wasn't aware that anyone had tried to use a file object to upload some data 😅 - But it makes sense to me. You could simply We could add a check here for I'd accept a PR for this. EDIT: It would need a web-specific test as well. |
Hey there, |
@ashil5834 Please add an example of where you think it should fail. |
@perry-mitchell here is the example, const { createClient } = require("webdav");
const client = createClient(
"https://devl-sync.citushealth.com/account/CHA_AU761ZA9",
{
username: "test",
password: "test",
}
)
async function first_folder() {
const directoryItems = await client.getDirectoryContents("/PN/test1_dir").then(function (contents) {
contents.forEach((items) => {
var des = items.filename.split('/')
var dest = des[des.length - 1]
const str = client.getFileContents(items.filename, { format: "text" }).then((content) => {
const wr = client.putFileContents('/Archive/first_dirtttt/' + dest, JSON.stringify(content)).catch((err)=>{
if(err) console.log(err)
});
})
})
})
}
first_folder() |
Ok, so that example (while mixing promises and callbacks) doesn't exactly indicate a potential failure. The promise should fail if there's a permissions issue. Try using async/await notation a bit more to ensure that you're seeing any errors. I've tidied up your example: const { createClient } = require("webdav");
const client = createClient(
"https://devl-sync.citushealth.com/account/CHA_AU761ZA9",
{
username: "test",
password: "test",
}
)
async function first_folder() {
const directoryItems = await client.getDirectoryContents("/PN/test1_dir");
for (const item in directoryItems) {
const des = item.filename.split('/');
const dest = des[des.length - 1];
const content = await client.getFileContents(item.filename, { format: "text" });
await client.putFileContents('/Archive/first_dirtttt/' + dest, JSON.stringify(content));
}
}
first_folder().catch(err => {
console.error(err);
}); |
@perry-mitchell |
Hi, |
Then it didn't set the header - therefore it can't be the reason it succeeded. That's why we have the detection to set it or not: https://github.com/perry-mitchell/webdav-client/blob/master/source/operations/putFileContents.ts#L31-L39 |
(Using the web version, v4.6.0)
Passing a File object to
putFileContents()
results incalculateDataLength()
throwing an error because it can't detect the size. PassingcontentLength: file.size
makes things work again like with 3.xCould
putFileContents()
be changed to officially support File objects? It seems simple enough, unless I'm missing something.The text was updated successfully, but these errors were encountered: