Comments (8)
I'm assuming you are wanting the file download URL.
You could do this a few of ways. One way is to use the file's ID or combine both the bucket name and the filename.
First thing you need to do would be to get the base download URL from the auth command.
b2.auth()
From the auth response you get the downloadUrl
:
{
accountId: '...',
apiUrl: '...',
downloadUrl: 'https://z000.backblaze.com'
}
You should probably cache this somewhere so you don't need to run b2.auth()
just to get it.
Then if you know the bucket name and you know the filename you just pull them together like so:
var baseDownloadUrl = authRespose.downloadUrl;
var bucketName = 'foo';
var fileName = 'beep-boop.png';
var fullDownloadUrl = [
baseDownloadUrl,
bucketName,
fileName
].join('/');
To give you https://z000.backblaze.com/foo/beep-boop.png
Or if you have the file's ID, which you could get from uploading the file using b2.uploadFile(...)
.
E.g. from the uploadResponse get the fileId
like so:
{
...
fileId: 'abcd234987324babdsakjhdasdsaa-dhkfhjkad`
...
}
Pull together a string like this:
Then if you know the bucket name and you know the filename you just pull them together like so:
var baseDownloadUrl = authRespose.downloadUrl;
var fileId = uploadResponse.fileId;
var fullDownloadUrl = [
baseDownloadUrl,
'b2api',
'v1',
'b2_download_file_by_id?' + fileId
].join('/');
Should give you something like:
https://z000.backblaze.com/b2api/v2/b2_download_file_by_id?abcd234987324babdsakjhdasdsaa-dhkfhjkad
from backblaze-b2.
Does that answer your question @expertsa ?
from backblaze-b2.
Thank you very much, it's perfectly clear !
from backblaze-b2.
I'll have a look at how the download URL's work later today and I'll post my
findings here :)
On Feb 16 2016, at 1:26 am, Expert SA [email protected]
wrote:Sorry to bother you again, do you know why those url are showing me the file
instead of downloading it?
I mean I know that right click save as can make it but if I a user wants to
download 6 files, it's easier if he just have to click on download rather than
right clicking on each files and save as.I hope it's possible, or maybe this will be possible after Beta.
from backblaze-b2.
@expertsa as far as I can tell, unless you send the mime type as an octet-stream, the browser will try and open it.
Here is a great article about the HTML5 download
attribute:
https://davidwalsh.name/download-attribute
That might help you with your problem.
from backblaze-b2.
Hi, thanks, working like a charm with the download attribute.
from backblaze-b2.
@yakovkhalinsky Are you open to the idea of exposing a function for this? Specifically: https://github.com/yakovkhalinsky/backblaze-b2/blob/master/lib/actions/file.js#L261
The example you gave above isn't very complicated, but it'd be far more convenient to write something like:
await b2.authorize();
const url = await b2.getFileDownloadUrl(fileId);
from backblaze-b2.
For future reference, the example code for downloading a file by fileId
in the above comment has a bug in the query string.
The corrected code looks like:
var baseDownloadUrl = authResponse.downloadUrl;
var fileId = uploadResponse.fileId;
var fullDownloadUrl = [
baseDownloadUrl,
'b2api',
'v1',
'b2_download_file_by_id?fileId=' + fileId
].join('/');
from backblaze-b2.
Related Issues (20)
- More operations with the filename without id HOT 1
- Is there a way to use a download url to download without auth headers? HOT 1
- Blocked by CORS policy HOT 5
- Help needed with use with Typescript HOT 1
- 1.6.0 not published to npm HOT 2
- axios in package.json in npm package still 0.18 HOT 4
- Byte length not same as content-length HOT 2
- Error getting bucket: Error: Request failed with status code 401 HOT 1
- How do I upload an image? HOT 1
- How do I get the url of my uploaded image? HOT 5
- connect ECONNREFUSED 127.0.0.1:80 HOT 3
- Recommend S3 API for basic needs HOT 6
- Find specific file using b2.listFileNames return files not relevant
- LIfecicle Rules. How to set them HOT 1
- on upload progress HOT 1
- Still maintained? HOT 5
- Latest released version (1.7.0) contains Axios CVE-2023-45857
- auto refresh authorizationToken
- Question on integration with GraphQL HOT 3
- Having some trouble with posting data HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backblaze-b2.