2 回答
TA贡献1827条经验 获得超9个赞
你想使用io.Pipe。你可以做:
reader, writer := io.Pipe()
errChan := make(chan error)
go func() {
errChan <- myFTP.Stor(path, reader)
}()
err := myXLS.Write(writer)
// handle err
err = <-errChan
// handle err
您可能希望writer.CloseWithError(err)ifxlsx.Write在不关闭编写器的情况下返回错误。
TA贡献1841条经验 获得超3个赞
你可以使用bytes.Buffer:
func uploadFileToQiniu(file *xlsx.File) (key string, err error) {
key = fmt.Sprintf("%s.xlsx", util.SerialNumber())
log.Debugf("file key is %s", key)
log.Debug("start to write file to a writer")
buf := new(bytes.Buffer)
err = file.Write(buf)
if err != nil {
log.Errorf("error caught when writing file: %v", err)
return
}
size := int64(buf.Len())
log.Debugf("file size is %d", size)
err = Put(key, size, buf)
if err != nil {
log.Errorf("error caught when uploading file: %v", err)
}
return key, nil
}
func Put(key string, size int64, reader io.Reader) error {}
- 2 回答
- 0 关注
- 198 浏览
添加回答
举报