b2: Fix link sharing #3314
This commit is contained in:
parent
a35aa1360e
commit
ccc416e62b
2 changed files with 41 additions and 0 deletions
|
@ -629,6 +629,10 @@ func (f *Fs) list(ctx context.Context, dir string, recurse bool, prefix string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Check that there are matching files
|
||||||
|
if len(response.Files) == 0 {
|
||||||
|
return fs.ErrorDirNotFound
|
||||||
|
}
|
||||||
for i := range response.Files {
|
for i := range response.Files {
|
||||||
file := &response.Files[i]
|
file := &response.Files[i]
|
||||||
// Finish if file name no longer has prefix
|
// Finish if file name no longer has prefix
|
||||||
|
@ -1227,6 +1231,15 @@ func (f *Fs) PublicLink(ctx context.Context, remote string) (link string, err er
|
||||||
} else {
|
} else {
|
||||||
RootURL = f.opt.DownloadURL
|
RootURL = f.opt.DownloadURL
|
||||||
}
|
}
|
||||||
|
_, err = f.NewObject(ctx, remote)
|
||||||
|
if err == fs.ErrorObjectNotFound || err == fs.ErrorNotAFile {
|
||||||
|
err = f.list(ctx, remote, false, "", 1, f.opt.Versions, func(remote string, object *api.File, isDirectory bool) error {
|
||||||
|
return errEndList
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
absPath := "/" + path.Join(f.root, remote)
|
absPath := "/" + path.Join(f.root, remote)
|
||||||
link = RootURL + "/file/" + urlEncode(f.bucket) + absPath
|
link = RootURL + "/file/" + urlEncode(f.bucket) + absPath
|
||||||
bucketType, err := f.getbucketType()
|
bucketType, err := f.getbucketType()
|
||||||
|
|
|
@ -301,6 +301,34 @@ server to the nearest millisecond appended to them.
|
||||||
Note that when using `--b2-versions` no file write operations are
|
Note that when using `--b2-versions` no file write operations are
|
||||||
permitted, so you can't upload files or delete them.
|
permitted, so you can't upload files or delete them.
|
||||||
|
|
||||||
|
### B2 and rclone link ###
|
||||||
|
|
||||||
|
Rclone supports generating file share links for private B2 buckets.
|
||||||
|
They can either be for a file for example:
|
||||||
|
|
||||||
|
```
|
||||||
|
./rclone link B2:bucket/path/to/file.txt
|
||||||
|
https://f002.backblazeb2.com/file/bucket/path/to/file.txt?Authorization=xxxxxxxx
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
or if run on a directory you will get:
|
||||||
|
|
||||||
|
```
|
||||||
|
./rclone link B2:bucket/path
|
||||||
|
https://f002.backblazeb2.com/file/bucket/path?Authorization=xxxxxxxx
|
||||||
|
```
|
||||||
|
|
||||||
|
you can then use the authorization token (the part of the url from the
|
||||||
|
`?Authorization=` on) on any file path under that directory. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
https://f002.backblazeb2.com/file/bucket/path/to/file1?Authorization=xxxxxxxx
|
||||||
|
https://f002.backblazeb2.com/file/bucket/path/file2?Authorization=xxxxxxxx
|
||||||
|
https://f002.backblazeb2.com/file/bucket/path/folder/file3?Authorization=xxxxxxxx
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
<!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/b2/b2.go then run make backenddocs -->
|
<!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/b2/b2.go then run make backenddocs -->
|
||||||
### Standard Options
|
### Standard Options
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue