@@ -12,6 +12,7 @@ import (
1212 "os"
1313 "path/filepath"
1414 "pinata/internal/common"
15+ "pinata/internal/config"
1516 cliConfig "pinata/internal/config"
1617 "pinata/internal/types"
1718 "strings"
@@ -26,26 +27,26 @@ const (
2627 CHUNK_SIZE = 10 * 1024 * 1024 // Chunk size
2728)
2829
29- func Upload (filePath string , groupId string , name string , verbose bool ) (types.UploadResponse , error ) {
30+ func Upload (filePath string , groupId string , name string , verbose bool , network string ) (types.UploadResponse , error ) {
3031
3132 stats , err := os .Stat (filePath )
3233 if err != nil {
3334 return types.UploadResponse {}, err
3435 }
3536
3637 if stats .Size () > MAX_SIZE_REGULAR_UPLOAD {
37- return uploadWithTUS (filePath , groupId , name , verbose , stats )
38+ return uploadWithTUS (filePath , groupId , name , verbose , stats , network )
3839 }
3940
40- return regularUpload (filePath , groupId , name , verbose )
41+ return regularUpload (filePath , groupId , name , verbose , network )
4142}
4243
4344type progressReader struct {
4445 r io.Reader
4546 bar * progressbar.ProgressBar
4647}
4748
48- func regularUpload (filePath string , groupId string , name string , verbose bool ) (types.UploadResponse , error ) {
49+ func regularUpload (filePath string , groupId string , name string , verbose bool , network string ) (types.UploadResponse , error ) {
4950
5051 jwt , err := common .FindToken ()
5152 if err != nil {
@@ -61,7 +62,7 @@ func regularUpload(filePath string, groupId string, name string, verbose bool) (
6162 return types.UploadResponse {}, err
6263 }
6364 body := & bytes.Buffer {}
64- contentType , err := createMultipartRequest (filePath , files , body , stats , groupId , name )
65+ contentType , err := createMultipartRequest (filePath , files , body , stats , groupId , name , network )
6566 if err != nil {
6667 return types.UploadResponse {}, err
6768 }
@@ -166,7 +167,7 @@ func formatSize(bytes int) string {
166167 return formattedSize
167168}
168169
169- func uploadWithTUS (filePath string , groupId string , name string , verbose bool , stats os.FileInfo ) (types.UploadResponse , error ) {
170+ func uploadWithTUS (filePath string , groupId string , name string , verbose bool , stats os.FileInfo , network string ) (types.UploadResponse , error ) {
170171 jwt , err := common .FindToken ()
171172 if err != nil {
172173 return types.UploadResponse {}, err
@@ -194,9 +195,15 @@ func uploadWithTUS(filePath string, groupId string, name string, verbose bool, s
194195 }
195196 defer f .Close ()
196197
198+ networkParam , err := cliConfig .GetNetworkParam (network )
199+ if err != nil {
200+ return types.UploadResponse {}, err
201+ }
202+
197203 // Create metadata
198204 metadata := map [string ]string {
199205 "filename" : filepath .Base (filePath ),
206+ "network" : networkParam ,
200207 }
201208 if groupId != "" {
202209 metadata ["group_id" ] = groupId
@@ -289,7 +296,7 @@ func uploadWithTUS(filePath string, groupId string, name string, verbose bool, s
289296 return response , nil
290297}
291298
292- func createMultipartRequest (filePath string , files []string , body io.Writer , stats os.FileInfo , groupId string , name string ) (string , error ) {
299+ func createMultipartRequest (filePath string , files []string , body io.Writer , stats os.FileInfo , groupId string , name string , network string ) (string , error ) {
293300 contentType := ""
294301 writer := multipart .NewWriter (body )
295302
@@ -322,6 +329,13 @@ func createMultipartRequest(filePath string, files []string, body io.Writer, sta
322329 }
323330 }
324331
332+ networkParam , err := config .GetNetworkParam (network )
333+ if err != nil {
334+ return "" , err
335+ }
336+
337+ err = writer .WriteField ("network" , networkParam )
338+
325339 if groupId != "" {
326340 err := writer .WriteField ("group_id" , groupId )
327341 if err != nil {
@@ -333,7 +347,7 @@ func createMultipartRequest(filePath string, files []string, body io.Writer, sta
333347 if name != "nil" {
334348 nameToUse = name
335349 }
336- err : = writer .WriteField ("name" , nameToUse )
350+ err = writer .WriteField ("name" , nameToUse )
337351 if err != nil {
338352 return contentType , err
339353 }
0 commit comments