-
Notifications
You must be signed in to change notification settings - Fork 2
/
file.go
41 lines (37 loc) · 967 Bytes
/
file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package parse
import (
"encoding/json"
"io"
)
// ParseFile is a Parse File that has been uploaded.
type ParseFile struct {
URL string `json:"url"`
Name string `json:"name"`
}
// UploadFile uploads a Parse File from the provided filename, contents and
// content type.
func (c *Client) UploadFile(name string, contents io.Reader, contentType string) (*ParseFile, error) {
uri := "/1/files/"+name
resp, err := c.do("POST", uri, contentType, contents)
c.trace("UploadFile", uri, contentType)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result *ParseFile
err = json.NewDecoder(resp.Body).Decode(&result)
return result, err
}
// DeleteFile removes a Parse File.
func (c *Client) DeleteFile(fileName string) error {
if c.masterKey == "" {
return ErrRequiresMasterKey
}
resp, err := c.doSimple("DELETE", "/1/files/"+fileName)
if err != nil {
return err
}
c.trace("DeleteFile", fileName)
defer resp.Body.Close()
return nil
}