Skip to content

Commit 660f30c

Browse files
committed
fix(go): fixing upload client
1 parent a3998d8 commit 660f30c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

templates/go/client.go.twig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,34 @@ func (client *Client) FileUpload(url string, headers map[string]interface{}, par
163163
currentChunk = int64(resp.Result.(map[string]interface{})["chunksUploaded"].(float64))
164164
}
165165
}
166+
167+
if fileInfo.Size() <= client.ChunkSize {
168+
if uploadId != "" && uploadId != "unique()" {
169+
headers["x-appwrite-id"] = uploadId
170+
}
171+
inputFile.Data = make([]byte, fileInfo.Size())
172+
_, err := file.Read(inputFile.Data)
173+
if err != nil && err != io.EOF {
174+
return nil, err
175+
}
176+
params[paramName] = inputFile
177+
178+
result, err = client.Call("POST", url, headers, params)
179+
if err != nil {
180+
return nil, err
181+
}
182+
183+
var parsed map[string]interface{}
184+
if strings.HasPrefix(result.Type, "application/json") {
185+
err = json.Unmarshal([]byte(result.Result.(string)), &parsed)
186+
if err == nil {
187+
uploadId, _ = parsed["$id"].(string)
188+
}
189+
}
190+
191+
return result, nil
192+
}
193+
166194
for i := currentChunk; i < numChunks; i++ {
167195
chunkSize := client.ChunkSize
168196
offset := int64(i) * chunkSize

0 commit comments

Comments
 (0)