APIs & Integrations

Not applicable

Unable to upload a file, 500 error

SOLVE

I am trying to upload a file to Hubspots file manager.
I'm doing this in golang and am repeatedly getting a 500 Error Code.

Add File Status Code: 500
{"status":"error","message":"internal error","correlationId":"0254b058-fc9d-43eb-b1c3-4f61fa97ae1e","requestId":"2f25106bb7657378dfc0a136553f0057"}

 path, err := os.Getwd()

if err != nil {
fmt.Print(err)
}
file, err := os.Open(path) // just pass the file name
if err != nil {
fmt.Print("Read File err: ", err)
}

body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("files", filepath.Base(path))
if err != nil {
fmt.Print(err)
}

_, err = io.Copy(part, file)

postURL := "http://api.hubapi.com/filemanager/api/v2/files?hapikey=" + hsapikey
client := http.Client{}
req, err := http.NewRequest("POST", postURL, body)
if err != nil {
fmt.Print(err)
}
req.Header.Set("Content-Type", "multipart/form-data")

resp, err := client.Do(req)
if err != nil {
fmt.Print("Upload Error: ", err)
}

fmt.Println("Add File Status Code: ", resp.StatusCode)
respbody, err := ioutil.ReadAll(resp.Body)
fmt.Println(fmt.Sprintf("%s", respbody))

I was originally trying to upload an image and have downscaled the attempt to just try and upload a basic text file to no avail.
Save me Hubspot, you're my only hope, thank you.

0 Upvotes
1 Accepted solution
Solution
Not applicable

Unable to upload a file, 500 error

SOLVE

Never Mind I solved it, didn't close the writer and set the File Path, I just assumed it would be placed in the root

View solution in original post

0 Upvotes
1 Reply 1
Solution
Not applicable

Unable to upload a file, 500 error

SOLVE

Never Mind I solved it, didn't close the writer and set the File Path, I just assumed it would be placed in the root

0 Upvotes