Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module github.com/qiniu/api.v7/v7
module github.com/qiniu/api.v7/v7

go 1.14
4 changes: 0 additions & 4 deletions storage/form_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ func (p *FormUploader) put(
var b bytes.Buffer
writer := multipart.NewWriter(&b)

if extra == nil {
extra = &PutExtra{}
}

if extra.OnProgress != nil {
data = &readerWithProgress{reader: data, fsize: size, onProgress: extra.OnProgress}
}
Expand Down
29 changes: 29 additions & 0 deletions storage/form_upload_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage

import (
"bufio"
"context"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -33,3 +34,31 @@ func TestFormUploadPutFile(t *testing.T) {
}
t.Logf("Key: %s, Hash:%s", putRet.Key, putRet.Hash)
}


func TestFormUploadPut(t *testing.T) {
var putRet PutRet
ctx := context.TODO()
putPolicy := PutPolicy{
Scope: testBucket,
DeleteAfterDays: 7,
}

// prepare file for test uploading
testLocalFile, err := ioutil.TempFile("", "TestFormUploadPutFile")
if err != nil {
t.Fatalf("ioutil.TempFile file failed, err: %v", err)
}
defer os.Remove(testLocalFile.Name())

upToken := putPolicy.UploadToken(mac)
testKey := fmt.Sprintf("testPutFileKey_%d", rand.Int())

data := bufio.NewReader(testLocalFile);

err = formUploader.Put(ctx, &putRet, upToken, testKey, data, int64(data.Size()), nil);
if err != nil {
t.Fatalf("FormUploader#PutFile() error, %s", err)
}
t.Logf("Key: %s, Hash:%s", putRet.Key, putRet.Hash)
}