Skip to content

Instantly share code, notes, and snippets.

@nemosupremo
Created April 13, 2016 23:52
Show Gist options
  • Save nemosupremo/c183c9f00385554abafe40c3105e9d36 to your computer and use it in GitHub Desktop.
Save nemosupremo/c183c9f00385554abafe40c3105e9d36 to your computer and use it in GitHub Desktop.
@@ -107,26 +107,34 @@ func createBody(params map[string]string, vidName string, vidFile *os.File, thum
}
go func() {
+ for key, val := range params {
+ if err := writer.WriteField(key, val); err != nil {
+ log.Error("Closing with error: " + err.Error())
+ pWriter.CloseWithError(err)
+ }
+ }
part, err := writer.CreateFormFile(vidName, vidFi.Name()+ext)
if err != nil {
+ log.Error("Closing with error: " + err.Error())
pWriter.CloseWithError(err)
}
if _, err := io.Copy(part, vidFile); err != nil {
+ log.Error("Closing with error: " + err.Error())
pWriter.CloseWithError(err)
}
if thumbFile != nil {
if thumbPart, err := writer.CreateFormFile(thumbName, thumbFiName); err == nil {
if _, err := io.Copy(thumbPart, thumbFile); err != nil {
+ log.Error("Closing with error: " + err.Error())
pWriter.CloseWithError(err)
}
} else {
+ log.Error("Closing with error: " + err.Error())
pWriter.CloseWithError(err)
}
}
- for key, val := range params {
- _ = writer.WriteField(key, val)
- }
if err := writer.Close(); err != nil {
+ log.Error("Closing with error: " + err.Error())
pWriter.CloseWithError(err)
}
pWriter.Close()
@@ -190,11 +198,13 @@ func UploadFacebookVideoTask(task *harvester.Task, amazonS3 *s3.S3, dbContext *d
os.Remove(videoFile.Name())
}()
if thumbFile, thumbErr := downloadFromS3(videoMetadata.FbThumbnail, "thumbnail"); thumbErr == nil {
- defer func() {
- thumbFile.Close()
- os.Remove(thumbFile.Name())
- }()
- defer thumbFile.Close()
+ if thumbFile != nil {
+ defer func() {
+ thumbFile.Close()
+ os.Remove(thumbFile.Name())
+ }()
+ defer thumbFile.Close()
+ }
params := map[string]string{
"title": videoMetadata.FbTitle,
"description": videoMetadata.FbDescription,
@@ -205,7 +215,7 @@ func UploadFacebookVideoTask(task *harvester.Task, amazonS3 *s3.S3, dbContext *d
req := goreq.Request{
Method: "POST",
Uri: "https://graph-video.facebook.com/v2.5/" + videoMetadata.Page + "/videos",
- Body: body,
+ Body: io.TeeReader(body, os.Stdout),
ContentType: contentType,
}
if res, reqErr := req.Do(); reqErr == nil {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment