- List - List Files
- Create - Create File
- Uploaded - Complete File Upload
- Delete - Delete File
- Update - Update File
List files.
Scopes: files:read files:write
package main
import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"github.com/polarsource/polar-go/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Files.List(ctx, polargo.Pointer(operations.CreateFilesListQueryParamOrganizationIDFilterStr(
"1dbfc517-0bbf-4301-9ba8-555ca42b9737",
)), nil, polargo.Pointer[int64](1), polargo.Pointer[int64](10))
if err != nil {
log.Fatal(err)
}
if res.ListResourceFileRead != nil {
for {
// handle items
res, err = res.Next()
if err != nil {
// handle error
}
if res == nil {
break
}
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
organizationID |
*operations.FilesListQueryParamOrganizationIDFilter | ➖ | Filter by organization ID. |
ids |
*operations.FileIDFilter | ➖ | Filter by file ID. |
page |
*int64 |
➖ | Page number, defaults to 1. |
limit |
*int64 |
➖ | Size of a page, defaults to 10. Maximum is 100. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FilesListResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.HTTPValidationError | 422 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Create a file.
Scopes: files:write
package main
import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"github.com/polarsource/polar-go/models/components"
"log"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Files.Create(ctx, components.CreateFileCreateDownloadable(
components.DownloadableFileCreate{
OrganizationID: polargo.Pointer("1dbfc517-0bbf-4301-9ba8-555ca42b9737"),
Name: "<value>",
MimeType: "<value>",
Size: 612128,
Upload: components.S3FileCreateMultipart{
Parts: []components.S3FileCreatePart{},
},
},
))
if err != nil {
log.Fatal(err)
}
if res.FileUpload != nil {
// handle response
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.FileCreate | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FilesCreateResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.HTTPValidationError | 422 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Complete a file upload.
Scopes: files:write
package main
import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"github.com/polarsource/polar-go/models/components"
"log"
"github.com/polarsource/polar-go/models/operations"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Files.Uploaded(ctx, "<value>", components.FileUploadCompleted{
ID: "<id>",
Path: "/boot",
Parts: []components.S3FileUploadCompletedPart{
components.S3FileUploadCompletedPart{
Number: 979613,
ChecksumEtag: "<value>",
ChecksumSha256Base64: polargo.Pointer("<value>"),
},
components.S3FileUploadCompletedPart{
Number: 979613,
ChecksumEtag: "<value>",
ChecksumSha256Base64: polargo.Pointer("<value>"),
},
components.S3FileUploadCompletedPart{
Number: 979613,
ChecksumEtag: "<value>",
ChecksumSha256Base64: polargo.Pointer("<value>"),
},
},
})
if err != nil {
log.Fatal(err)
}
if res.ResponseFilesUploaded != nil {
switch res.ResponseFilesUploaded.Type {
case operations.FilesUploadedResponseFilesUploadedTypeDownloadable:
// res.ResponseFilesUploaded.DownloadableFileRead is populated
case operations.FilesUploadedResponseFilesUploadedTypeProductMedia:
// res.ResponseFilesUploaded.ProductMediaFileRead is populated
case operations.FilesUploadedResponseFilesUploadedTypeOrganizationAvatar:
// res.ResponseFilesUploaded.OrganizationAvatarFileRead is populated
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string |
✔️ | The file ID. |
fileUploadCompleted |
components.FileUploadCompleted | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FilesUploadedResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.NotPermitted | 403 | application/json |
| apierrors.ResourceNotFound | 404 | application/json |
| apierrors.HTTPValidationError | 422 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Delete a file.
Scopes: files:write
package main
import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"log"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Files.Delete(ctx, "<value>")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string |
✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FilesDeleteResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.NotPermitted | 403 | application/json |
| apierrors.ResourceNotFound | 404 | application/json |
| apierrors.HTTPValidationError | 422 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |
Update a file.
Scopes: files:write
package main
import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"github.com/polarsource/polar-go/models/components"
"log"
"github.com/polarsource/polar-go/models/operations"
)
func main() {
ctx := context.Background()
s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
res, err := s.Files.Update(ctx, "<value>", components.FilePatch{})
if err != nil {
log.Fatal(err)
}
if res.ResponseFilesUpdate != nil {
switch res.ResponseFilesUpdate.Type {
case operations.FilesUpdateResponseFilesUpdateTypeDownloadable:
// res.ResponseFilesUpdate.DownloadableFileRead is populated
case operations.FilesUpdateResponseFilesUpdateTypeProductMedia:
// res.ResponseFilesUpdate.ProductMediaFileRead is populated
case operations.FilesUpdateResponseFilesUpdateTypeOrganizationAvatar:
// res.ResponseFilesUpdate.OrganizationAvatarFileRead is populated
}
}
}| Parameter | Type | Required | Description |
|---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string |
✔️ | The file ID. |
filePatch |
components.FilePatch | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.FilesUpdateResponse, error
| Error Type | Status Code | Content Type |
|---|---|---|
| apierrors.NotPermitted | 403 | application/json |
| apierrors.ResourceNotFound | 404 | application/json |
| apierrors.HTTPValidationError | 422 | application/json |
| apierrors.APIError | 4XX, 5XX | */* |