Example usage
Closed this issue · 2 comments
Hi, after your help, I managed to get to the API, but now I've found myself not knowing what to do next.
The wiki site states that the simplest usage is:
const file: Uri = await fileDownloader.downloadFile(
Uri.parse(url),
filename,
context
);
I should replace url, filename and context with something, and I believe it would look more or less like this:
const file: Uri = await fileDownloader.downloadFile(
Uri.parse('https://upload.wikimedia.org/wikipedia/commons/7/77/Delete_key1.jpg'),
'Delete_key1.jpg',
context
);
but I don't know what the context is. Do you have an example usage somewhere?
Hi @generalpsycha,
The context here is the VS Code extension's context, provided to you when your extension is activated.
To be more specific, your VS Code extension's activation function should look like this:
export function activate(context: vscode.ExtensionContext)
{ ... }
The argument provided there is the context
we need.
Thank you again, @daniv-msft!
Yes, this is exactly what I needed. My download method looks like this:
async function fileDownload(context: vscode.ExtensionContext) {
const fileDownloader: FileDownloader = await getApi();
const file: Uri = await fileDownloader.downloadFile(
Uri.parse('https://upload.wikimedia.org/wikipedia/commons/7/77/Delete_key1.jpg'),
'Delete_key1.jpg',
context
);
console.log(file);
}
and it worked, the file has been downloaded!
Closing the issue