第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

.xlsx文件上傳到谷歌云存儲(chǔ)

.xlsx文件上傳到谷歌云存儲(chǔ)

Go
慕姐8265434 2022-08-24 11:42:50
我用Go編寫了這個(gè)API,它使用excelize創(chuàng)建一個(gè).xlsx文件,從數(shù)據(jù)庫(kù)中獲取的數(shù)據(jù),我想上傳到私有GCS存儲(chǔ)桶。但問(wèn)題是在我上傳文件后,它說(shuō)文件類型不是 。application/zipapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheettype Connection struct {    Credential    string    BucketName    string    APIKey        string    ProjectID     string    AccessToken   string    BaseURL       string    GcpCredential *google.Credentials}func (conn *Connection) Upload(url, name string) (err error) {    ctx := context.Background()    client, err := storage.NewClient(ctx, option.WithCredentialsFile(conn.Credential))    if err != nil {        return err    }    err = write(client, conn.BucketName, name, url)    return err}func write(client *storage.Client, bucket, object, url string) error {    ctx := context.Background()    f, err := os.Open(url)    if err != nil {        return err    }    defer f.Close()    wc := client.Bucket(bucket).Object(object).NewWriter(ctx)    _, err = io.Copy(wc, f)    if err != nil {        return err    }    if err := wc.Close(); err != nil {        return err    }    return nil}//In other file, generate excel file and upload it using above codexlsx := excelize.NewFile()//setup file content...//save to local machine located in uploadURLerr = xlsx.SaveAs(uploadURL)//then upload to GCS bucketerr = h.Googlestorage.Upload(uploadURL, fileNameInGCS)if err != nil {    SendBadRequest(w, err.Error())    return}//then generate signed URL for client to access the file這是一個(gè)問(wèn)題,因?yàn)楫?dāng)我生成文件的簽名URL時(shí),它被下載為.zip文件,而不是.xlsx。"{file path in bucket}.xlsx?Expires=1617698911&GoogleAccessId={googleAccessID}&Signature={someGeneratedSignature}"如何解決此問(wèn)題?我上傳文件的方式有問(wèn)題嗎?
查看完整描述

1 回答

?
長(zhǎng)風(fēng)秋雁

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊

您可以使用 ObjectHandle.Update 函數(shù)

    _, err := client.Bucket(bucket).Object(object).Update(ctx, storage.ObjectAttrsToUpdate{
        ContentType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    })



查看完整回答
反對(duì) 回復(fù) 2022-08-24
  • 1 回答
  • 0 關(guān)注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)