Skip to content

Commit 9f9b1ae

Browse files
committed
Include the object size in response to uploads
Closes #722.
1 parent 3c8e21b commit 9f9b1ae

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎fakestorage/object.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (o Object) MarshalJSON() ([]byte, error) {
5959
temp := struct {
6060
BucketName string `json:"bucket"`
6161
Name string `json:"name"`
62-
Size int64 `json:"-"`
62+
Size int64 `json:"size,string"`
6363
ContentType string `json:"contentType"`
6464
ContentEncoding string `json:"contentEncoding"`
6565
Content []byte `json:"-"`
@@ -76,6 +76,7 @@ func (o Object) MarshalJSON() ([]byte, error) {
7676
Name: o.Name,
7777
ContentType: o.ContentType,
7878
ContentEncoding: o.ContentEncoding,
79+
Size: o.Size,
7980
Content: o.Content,
8081
Crc32c: o.Crc32c,
8182
Md5Hash: o.Md5Hash,
@@ -97,7 +98,7 @@ func (o *Object) UnmarshalJSON(data []byte) error {
9798
temp := struct {
9899
BucketName string `json:"bucket"`
99100
Name string `json:"name"`
100-
Size int64 `json:"-"`
101+
Size int64 `json:"size,string"`
101102
ContentType string `json:"contentType"`
102103
ContentEncoding string `json:"contentEncoding"`
103104
Content []byte `json:"-"`
@@ -117,6 +118,7 @@ func (o *Object) UnmarshalJSON(data []byte) error {
117118
o.Name = temp.Name
118119
o.ContentType = temp.ContentType
119120
o.ContentEncoding = temp.ContentEncoding
121+
o.Size = temp.Size
120122
o.Content = temp.Content
121123
o.Crc32c = temp.Crc32c
122124
o.Md5Hash = temp.Md5Hash

‎fakestorage/upload_test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func TestServerClientObjectWriter(t *testing.T) {
8282
n, baseContent)
8383
}
8484

85+
if returnedSize := w.Attrs().Size; returnedSize != int64(len(content)) {
86+
t.Errorf("wrong writer.Attrs() size returned\nwant %d\ngot %d", len(content), returnedSize)
87+
}
8588
if returnedChecksum := w.Attrs().CRC32C; returnedChecksum != u32Checksum {
8689
t.Errorf("wrong writer.Attrs() checksum returned\nwant %d\ngot %d", u32Checksum, returnedChecksum)
8790
}

0 commit comments

Comments
 (0)