Skip to content

Commit e73af55

Browse files
committed
1 parent 51c6c2d commit e73af55

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

polycode/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@ type GetLinkResponse struct {
160160

161161
// PutFileRequest represents the JSON structure for put file operations
162162
type PutFileRequest struct {
163-
Key string `json:"key"`
164-
Content string `json:"content"`
163+
Key string `json:"key"`
164+
Content string `json:"content"`
165+
FilePath string `json:"filePath"`
165166
}
166167

167168
type DeleteFileRequest struct {

polycode/filestore.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ func (d FileStore) Save(path string, data []byte) error {
101101
return nil
102102
}
103103

104+
func (d FileStore) Upload(path string, filePath string) error {
105+
req := PutFileRequest{
106+
Key: path,
107+
FilePath: filePath,
108+
}
109+
110+
err := d.client.PutFile(d.sessionId, req)
111+
if err != nil {
112+
fmt.Printf("failed to put file: %s\n", err.Error())
113+
return err
114+
}
115+
116+
return nil
117+
}
118+
104119
func (d FileStore) GetUploadLink(path string) (string, error) {
105120
req := GetFileRequest{
106121
Key: path,
@@ -204,6 +219,21 @@ func (f Folder) Save(name string, data []byte) error {
204219
return nil
205220
}
206221

222+
func (f Folder) Upload(name string, filePath string) error {
223+
req := PutFileRequest{
224+
Key: f.name + "/" + name,
225+
FilePath: filePath,
226+
}
227+
228+
err := f.client.PutFile(f.sessionId, req)
229+
if err != nil {
230+
fmt.Printf("failed to put file: %s\n", err.Error())
231+
return err
232+
}
233+
234+
return nil
235+
}
236+
207237
func newFileStore(client *ServiceClient, sessionId string) FileStore {
208238
return FileStore{
209239
client: client,

0 commit comments

Comments
 (0)