2015-12-07 04:01:03 +00:00
|
|
|
package src
|
|
|
|
|
|
|
|
//from yadisk
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PerformUpload does the actual upload via unscoped PUT request.
|
2015-12-30 13:30:57 +00:00
|
|
|
func (c *Client) PerformUpload(url string, data io.Reader) (err error) {
|
2015-12-07 04:01:03 +00:00
|
|
|
req, err := http.NewRequest("PUT", url, data)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
//c.setRequestScope(req)
|
|
|
|
|
2016-02-15 16:43:18 +00:00
|
|
|
resp, err := c.HTTPClient.Do(req)
|
2015-12-07 04:01:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer CheckClose(resp.Body, &err)
|
|
|
|
|
|
|
|
if resp.StatusCode != 201 {
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("upload error [%d]: %s", resp.StatusCode, string(body[:]))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|