mirror of https://github.com/Xhofe/alist
fix(webdav): sharepoint upload
parent
e4df146043
commit
42c0e438d5
|
@ -213,7 +213,11 @@ func (driver WebDav) Upload(file *model.FileStream, account *model.Account) erro
|
|||
}
|
||||
c := driver.NewClient(account)
|
||||
path := utils.Join(file.ParentPath, file.Name)
|
||||
err := c.WriteStream(driver.WebDavPath(path), file, 0644)
|
||||
callback := func(r *http.Request) {
|
||||
r.Header.Set("Content-Type", file.GetMIMEType())
|
||||
r.ContentLength = int64(file.GetSize())
|
||||
}
|
||||
err := c.WriteStream(driver.WebDavPath(path), file, 0644, callback)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -396,7 +396,7 @@ func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadClos
|
|||
|
||||
// Write writes data to a given path
|
||||
func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
|
||||
s, err := c.put(path, bytes.NewReader(data))
|
||||
s, err := c.put(path, bytes.NewReader(data), nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
s, err = c.put(path, bytes.NewReader(data))
|
||||
s, err = c.put(path, bytes.NewReader(data), nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -425,14 +425,14 @@ func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) {
|
|||
}
|
||||
|
||||
// WriteStream writes a stream
|
||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error) {
|
||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode, callback func(r *http.Request)) (err error) {
|
||||
|
||||
err = c.createParentCollection(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := c.put(path, stream)
|
||||
s, err := c.put(path, stream, callback)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -211,7 +211,7 @@ func cmdPut(c *d.Client, p0, p1 string) (err error) {
|
|||
}
|
||||
defer stream.Close()
|
||||
|
||||
if err = c.WriteStream(p0, stream, 0644); err == nil {
|
||||
if err = c.WriteStream(p0, stream, 0644, nil); err == nil {
|
||||
fmt.Println("Put: " + p1 + " -> " + p0)
|
||||
}
|
||||
return
|
||||
|
|
|
@ -192,13 +192,14 @@ func (c *Client) copymove(method string, oldpath string, newpath string, overwri
|
|||
return newPathError(method, oldpath, s)
|
||||
}
|
||||
|
||||
func (c *Client) put(path string, stream io.Reader) (status int, err error) {
|
||||
rs, err := c.req("PUT", path, stream, nil)
|
||||
func (c *Client) put(path string, stream io.Reader, callback func(r *http.Request)) (status int, err error) {
|
||||
rs, err := c.req("PUT", path, stream, callback)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rs.Body.Close()
|
||||
|
||||
//all, _ := io.ReadAll(rs.Body)
|
||||
//logrus.Debugln("put res: ", string(all))
|
||||
status = rs.StatusCode
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue