### Download Files with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet provides examples for downloading files from UFile. It covers both standard file download and streaming download, demonstrating the use of the `Download` method. ```go // 加载配置,创建请求 config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } // 普通下载 err = req.Download("DownLoadURL") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } // 流式下载 err = req.Download("buffer", "KeyName") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Perform Multipart Upload with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet shows how to perform a standard multipart upload using the `MPut` method of the UFile Go SDK. It loads configuration, creates a file request, and initiates the upload. ```go // 加载配置,创建请求 config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } err = req.MPut("FilePath", "KeyName", "MimeType") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Query File Metadata with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet shows how to retrieve basic information and metadata about a file stored in UFile using the `HeadFile` method. It initializes the SDK and makes a request for file headers. ```go config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } err = req.HeadFile("KeyName") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Perform Form Upload with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet demonstrates how to perform a form-based file upload using the UFile Go SDK. It initializes the SDK with a configuration file, creates a new file request, and then uploads a file using `PostFile`. ```go // 加载配置,创建请求 config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } err = req.PostFile("FilePath", "KeyName", "MimeType") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Copy Files with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet demonstrates how to copy a file within UFile, potentially between different buckets, using the `Copy` method. It specifies the destination key, source bucket, and source key. ```go config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } err = req.Copy("DstkeyName", "SrcBucketName", "SrcKeyName") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Perform Multipart Uploads with Callbacks using UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet demonstrates various multipart upload methods that support callbacks: synchronous (`MPutWithPolicy`), asynchronous (`AsyncMPutWithPolicy`), and asynchronous concurrent (`AsyncUploadWithPolicy`). It shows how to integrate custom policies with uploads. ```go // 加载配置,创建请求 config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } // 同步分片上传回调 err = req.MPutWithPolicy("FilePath", "KeyName", "MimeType", "Policy") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } // 异步分片上传回调 err = req.AsyncMPutWithPolicy("FilePath", "KeyName", "MimeType", "Policy") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } // 异步分片并发上传回调 jobs := 20 // 并发数为 20 err = req.AsyncUploadWithPolicy("FilePath", "KeyName", "MimeType", jobs, "Policy") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Perform Streaming Uploads with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet illustrates two types of streaming uploads: for small local files using `IOPut` and for large files using `IOMutipartAsyncUpload`. It shows how to open a file and stream its content to UFile. ```go if err != nil { log.Fatal(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { log.Fatal(err.Error()) } // 流式上传本地小文件 f, err := os.Open("FilePath") if err != nil { panic(err.Error()) } err = req.IOPut(f, "KeyName", "") f.Close() if err != nil { log.Fatalf("%s\n", req.DumpResponse(true)) } // 流式上传大文件 f1, err := os.Open("FilePath1") if err != nil { panic(err.Error()) } err = req.IOMutipartAsyncUpload(f1, "KeyName", "") f1.Close() if err != nil { log.Fatalf("%s\n", req.DumpResponse(true)) } ``` -------------------------------- ### Compare Local and Remote File ETag with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet shows how to compare the ETag of a local file with its corresponding remote file in UFile using the `CompareFileEtag` method. This is useful for verifying file integrity or synchronization. ```go config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } err = req.CompareFileEtag("KeyName", "FilePath") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Delete Files with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet demonstrates how to delete a file from UFile using the `DeleteFile` method. It initializes the SDK and sends a request to remove the specified file. ```go config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } err = req.DeleteFile("KeyName") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Restore Archived Files with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet shows how to restore an archived file in UFile using the `Restore` method. This is typically used for files stored in cold or archive storage classes to make them accessible. ```go config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } err = req.Restore("KeyName") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` -------------------------------- ### Change File Storage Class with UFile Go SDK Source: https://github.com/ufilesdk-dev/ufile-gosdk/blob/master/README.md This snippet demonstrates how to change the storage class of an existing file in UFile using the `ClassSwitch` method. This allows moving files between different storage tiers. ```go config, err := ufsdk.LoadConfig("config.json") if err != nil { panic(err.Error()) } req, err := ufsdk.NewFileRequest(config, nil) if err != nil { panic(err.Error()) } err = req.ClassSwitch("KeyName", "StorageClass") if err != nil { log.Println("DumpResponse:", string(req.DumpResponse(true))) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.