我已经使用24SevenOffice API在Node.js中工作了一段时间,最近一次是使用FileService
。我还没有从API下载文件,所以我希望就如何完成此操作提出一些建议。该文档介绍了四种下载文件的相关方法(PrepareFileDownload
,DownloadFileChunck
,HashFile
,EndFileDownload
)。
您需要一个API密钥和一个24sevenoffice-account。我只是在寻找有关如何完成此操作的解释:
writestream
/ readstream
使用哪些其他功能/方法等可能很重要?chunckNum
输入是什么意思? (chunckNum
是DownloadFileChunck
方法中的输入名称)DownloadFileChunck
方法的响应。 (我想这是我必须使用其他一些方法/功能的地方)我尝试了几种将这四种方法结合起来的方法,但是我真的不知道自己在做什么,所以我决定寻求帮助。我认为我对HashFile
方法并没有尝试太多。以PrepareFileDownload
开头并以EndFileDownload
结尾是有意义的,但是在这两者之间我该怎么办?
这仅用于显示方法。不希望此代码起作用。显然,它需要执行一些操作来存储文件内容或其他内容。该代码不包含方法HashFile
。
//24sevenoffice.js is another module that takes care of logging in with the API key, username, password and all that
const office = require("./24sevenoffice.js");
const fs = require("fs");
const chuncksize = ;
//I realize that I might be on my way to callback hell here, but I will clean this up later. This is just for showing you guys.
office.login((err) => {
if (err){
console.log(err);
}
office.service("https://webservices.24sevenoffice.com/file/V001/FileService.asmx?wsdl", (err, FileService) => {
if (err){
console.log(err);
}
else {
//logging in works fine
FileService.PrepareFileDownload({FileId: 2908751, FolderId: 1256067, CheckOut: false}, (err, bytes) => {
if(err){
console.log(err);
}
else{
//preparefiledownload also works fine and I'm getting the TmpId and the length of the file as response.
console.log(bytes);
//My best guess for the Chuncknum input is that it states how many chuncks I want the file to be downloaded in
//Then it would make sense to divide the length by some constant chunksize, I hope
let CNUM = Math.floor(bytes.PrepareFileDownloadResult.Length/chuncksize);
if(CNUM == 0){
CNUM = 1;
}
let TMPID = new String(bytes.PrepareFileDownloadResult.TmpId);
//This is how I think the EndFileDownload method should look:
FileService.DownloadFileChunk({TmpId: TMPID, ChunckNum: CNUM}, (err, response) => {
if(err){
console.log(err);
}
else{
console.dir(response);
}
});
//This is how I think the EndFileDownload method should look:
FileService.EndFileDownload({TmpId: TMPID}, (err, response) => {
if(err){
console.log(err);
}
else{
console.log(response);
}
});
}
});
}
});
});