stmcginnis / gofish

Gofish is a Golang client library for DMTF Redfish and SNIA Swordfish interaction.
BSD 3-Clause "New" or "Revised" License
224 stars 117 forks source link

BUG: CreateFormFile method expects just filename, not full filepath #131

Closed mikeletux closed 3 years ago

mikeletux commented 3 years ago

Hey Sean,

I was trying to implement SimpleUpdate in our terraform provider and, when uploading FW packages to the FW inventory, I found out that the API was returning a 500 error with no error description (favorite developer kind of issue 😆 ). It was driving me crazy but after a while I saw the following (please check line 387):

https://github.com/stmcginnis/gofish/blob/f20250aa04e04c84b6dfec05391eb1d542675e29/client.go#L385-L389

As per current implementation, on CreateFormFile method, we use as filename the file.Name() method, which actually returns the whole path of the file.

To solve this, we need to just grab the filename from the path, using for instance filepath.Base() method. Something like this

if file, ok := reader.(*os.File); ok {
            // Add a file stream
            if partWriter, err = payloadWriter.CreateFormFile(key, filepath.Base(file.Name())); err != nil {
                return nil, err
            }

I will send a PR that implements that, just wanted to open this issue for reference, just in case anyone else faces the same in the future.

Thanks! /Miguel

mikeletux commented 3 years ago

Merged. Closing issue.