Documentation ¶
Index ¶
- Constants
- func UploadFilePart(b2PartInfo FilePartInfo, chunkNum int, checksum string, contents []byte) error
- type Auth
- func (b2Auth Auth) CancelLargeFile(fileID string) (bool, error)
- func (b2Auth Auth) DeleteFile(b2ID string, name string) bool
- func (b2Auth Auth) DownloadById(id string) ([]byte, error)
- func (b2Auth Auth) FinishLargeFile(fileID string, checksums []string) (LargeFile, error)
- func (b2Auth Auth) GetUploadPartURL(b2File StartFile) (FilePartInfo, error)
- func (b2Auth Auth) GetUploadURL(bucketID string) (FileInfo, error)
- func (b2Auth Auth) ListAllFiles(bucketID string) (FileList, error)
- func (b2Auth Auth) ListFiles(bucketID string, count int, startName string, startID string) (FileList, error)
- func (b2Auth Auth) ListNFiles(bucketID string, count int) (FileList, error)
- func (b2Auth Auth) PartialDownloadById(id string, begin int, end int) ([]byte, error)
- func (b2Auth Auth) StartLargeFile(filename string, bucketID string) (StartFile, error)
- type File
- type FileInfo
- type FileList
- type FilePartInfo
- type LargeFile
- type StartFile
Constants ¶
const APICancelLargeFile = "b2_cancel_large_file"
const APIDeleteFile = "b2_delete_file_version"
const APIDownloadById string = "b2_download_file_by_id"
const APIFinishLargeFile = "b2_finish_large_file"
const APIGetUploadPartURL string = "b2_get_upload_part_url"
const APIGetUploadURL string = "b2_get_upload_url"
const APIListFileVersions = "b2_list_file_versions"
const APIStartLargeFile string = "b2_start_large_file"
const AuthURL string = "https://api.backblazeb2.com/b2api/v2/b2_authorize_account"
Variables ¶
This section is empty.
Functions ¶
func UploadFilePart ¶
func UploadFilePart( b2PartInfo FilePartInfo, chunkNum int, checksum string, contents []byte, ) error
UploadFilePart uploads a single chunk of file data to the URL provided by GetUploadPartURL. Each subsequent chunk should increment chunkNum, with the first chunk starting at 1 (not 0). Each chunk should be provided with a SHA1 checksum as well.
Types ¶
type Auth ¶
type Auth struct { AbsoluteMinimumPartSize int `json:"absoluteMinimumPartSize"` AccountID string `json:"accountId"` Allowed struct { BucketID string `json:"bucketId"` BucketName string `json:"bucketName"` Capabilities []string `json:"capabilities"` NamePrefix any `json:"namePrefix"` } `json:"allowed"` APIURL string `json:"apiUrl"` AuthorizationToken string `json:"authorizationToken"` DownloadURL string `json:"downloadUrl"` RecommendedPartSize int `json:"recommendedPartSize"` S3APIURL string `json:"s3ApiUrl"` }
func AuthorizeAccount ¶
func (Auth) CancelLargeFile ¶
CancelLargeFile cancels an in-progress large file upload and deletes the partial file from the B2 bucket. Returns true if the file was successfully deleted, otherwise false. Requires the fileID returned from StartLargeFile.
func (Auth) DeleteFile ¶
DeleteFile removes a file from B2 using the file's ID and name. Both fields are required, and are provided when a file finishes uploading.
func (Auth) DownloadById ¶
DownloadById downloads an entire file (regardless of size) from B2.
func (Auth) FinishLargeFile ¶
FinishLargeFile completes the chunked upload process. The FileID from calling StartLargeFile should be used here, and all checksums from UploadFilePart should be passed a string-ified array. For example: "['checksum1', 'checksum2']"
func (Auth) GetUploadPartURL ¶
func (b2Auth Auth) GetUploadPartURL( b2File StartFile, ) (FilePartInfo, error)
GetUploadPartURL generates a URL and token for uploading individual chunks of a file to B2. It requires a StartFile struct returned by StartLargeFile, which contains the unique file ID for this new file.
func (Auth) GetUploadURL ¶
GetUploadURL returns a FileInfo struct containing the URL to use for uploading a file, the ID of the bucket the file will be put in, and a token for authenticating the upload request.
func (Auth) ListAllFiles ¶
ListAllFiles is a helper function for simply fetching all available files in the bucket. If more than 100 files exist, the FileList struct will contain NextFileName and NextFileID fields that can be used with ListFiles to fetch the remainder.
func (Auth) ListFiles ¶
func (b2Auth Auth) ListFiles( bucketID string, count int, startName string, startID string, ) (FileList, error)
ListFiles lists all files in the specified bucket up to a maximum of `count`, starting with `startName` and, optionally, `startID`. If count is set to an invalid or negative value, the default number of files returned is 100. If startName or startID are not set, the bucket will list all files
func (Auth) ListNFiles ¶
ListNFiles is similar to ListAllFiles, but allows explicitly stating how many files you want returned in the response.
func (Auth) PartialDownloadById ¶
PartialDownloadById downloads a file from B2 with a specified begin and end byte. For example, setting begin to 0 and end to 99 will download only the first 99 bytes of the file.
type File ¶
type File struct { AccountID string `json:"accountId"` Action string `json:"action"` BucketID string `json:"bucketId"` ContentLength int `json:"contentLength"` ContentMd5 string `json:"contentMd5"` ContentSha1 string `json:"contentSha1"` ContentType string `json:"contentType"` FileID string `json:"fileId"` FileInfo struct { } `json:"fileInfo"` FileName string `json:"fileName"` FileRetention struct { IsClientAuthorizedToRead bool `json:"isClientAuthorizedToRead"` Value any `json:"value"` } `json:"fileRetention"` LegalHold struct { IsClientAuthorizedToRead bool `json:"isClientAuthorizedToRead"` Value any `json:"value"` } `json:"legalHold"` ServerSideEncryption struct { Algorithm string `json:"algorithm"` Mode string `json:"mode"` } `json:"serverSideEncryption"` UploadTimestamp int64 `json:"uploadTimestamp"` }
File represents the data returned by UploadFile
func UploadFile ¶
func UploadFile( b2Info FileInfo, filename string, checksum string, contents []byte, ) (File, error)
UploadFile uploads file byte content to B2 alongside a name for the file and a SHA1 checksum for the byte content. It returns a File object, which contains fields such as FileID and ContentLength which can be stored and used later to download the file.
type FileInfo ¶
type FileInfo struct { BucketID string `json:"bucketId"` UploadURL string `json:"uploadUrl"` AuthorizationToken string `json:"authorizationToken"` }
FileInfo represents the data returned by GetUploadURL
type FileList ¶
type FileList struct { Files []struct { AccountID string `json:"accountId"` Action string `json:"action"` BucketID string `json:"bucketId"` ContentLength int `json:"contentLength"` ContentSha1 string `json:"contentSha1"` ContentMd5 string `json:"contentMd5"` ContentType string `json:"contentType"` FileID string `json:"fileId"` FileInfo struct { SrcLastModifiedMillis string `json:"src_last_modified_millis"` } `json:"fileInfo"` FileName string `json:"fileName"` FileRetention struct { IsClientAuthorizedToRead bool `json:"isClientAuthorizedToRead"` Value struct { Mode string `json:"mode"` RetainUntilTimestamp string `json:"retainUntilTimestamp"` } `json:"value"` } `json:"fileRetention"` LegalHold struct { IsClientAuthorizedToRead bool `json:"isClientAuthorizedToRead"` Value string `json:"value"` } `json:"legalHold"` ReplicationStatus string `json:"replicationStatus"` ServerSideEncryption struct { Algorithm string `json:"algorithm"` Mode string `json:"mode"` } `json:"serverSideEncryption"` UploadTimestamp int `json:"uploadTimestamp"` } `json:"files"` NextFileName string `json:"nextFileName"` NextFileID string `json:"nextFileId"` }
type FilePartInfo ¶
type FilePartInfo struct { FileID string `json:"fileId"` UploadURL string `json:"uploadUrl"` AuthorizationToken string `json:"authorizationToken"` }
FilePartInfo represents the data returned by GetUploadPartURL
type LargeFile ¶
type LargeFile struct { AccountID string `json:"accountId"` Action string `json:"action"` BucketID string `json:"bucketId"` ContentLength int `json:"contentLength"` ContentMd5 any `json:"contentMd5"` ContentSha1 string `json:"contentSha1"` ContentType string `json:"contentType"` FileID string `json:"fileId"` FileInfo struct { } `json:"fileInfo"` FileName string `json:"fileName"` FileRetention struct { IsClientAuthorizedToRead bool `json:"isClientAuthorizedToRead"` Value any `json:"value"` } `json:"fileRetention"` LegalHold struct { IsClientAuthorizedToRead bool `json:"isClientAuthorizedToRead"` Value any `json:"value"` } `json:"legalHold"` ServerSideEncryption struct { Algorithm string `json:"algorithm"` Mode string `json:"mode"` } `json:"serverSideEncryption"` UploadTimestamp int64 `json:"uploadTimestamp"` }
LargeFile represents the file object created by FinishLargeFile
type StartFile ¶
type StartFile struct { AccountID string `json:"accountId"` Action string `json:"action"` BucketID string `json:"bucketId"` ContentLength int `json:"contentLength"` ContentSha1 string `json:"contentSha1"` ContentType string `json:"contentType"` FileID string `json:"fileId"` FileInfo struct { } `json:"fileInfo"` FileName string `json:"fileName"` FileRetention struct { IsClientAuthorizedToRead bool `json:"isClientAuthorizedToRead"` Value struct { Mode any `json:"mode"` RetainUntilTimestamp any `json:"retainUntilTimestamp"` } `json:"value"` } `json:"fileRetention"` LegalHold struct { IsClientAuthorizedToRead bool `json:"isClientAuthorizedToRead"` Value any `json:"value"` } `json:"legalHold"` ServerSideEncryption struct { Algorithm any `json:"algorithm"` Mode any `json:"mode"` } `json:"serverSideEncryption"` UploadTimestamp int64 `json:"uploadTimestamp"` }
StartFile represents the data returned by StartLargeFile