Files
Create File
Create a file.
Scopes: files:write
POST
/
v1
/
files
/
Go (SDK)
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
}
}from polar_sdk import Polar
with Polar(
access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:
res = polar.files.create(request={
"name": "<value>",
"mime_type": "<value>",
"size": 612128,
"upload": {
"parts": [],
},
"service": "downloadable",
})
# Handle response
print(res)import { Polar } from "@polar-sh/sdk";
const polar = new Polar({
accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});
async function run() {
const result = await polar.files.create({
organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
name: "<value>",
mimeType: "<value>",
size: 612128,
upload: {
parts: [],
},
service: "downloadable",
});
console.log(result);
}
run();declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Components;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$request = new Components\DownloadableFileCreate(
organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737',
name: '<value>',
mimeType: '<value>',
size: 612128,
upload: new Components\S3FileCreateMultipart(
parts: [],
),
);
$response = $sdk->files->create(
request: $request
);
if ($response->fileUpload !== null) {
// handle response
}curl --request POST \
--url https://api.polar.sh/v1/files/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"mime_type": "<string>",
"size": 123,
"upload": {
"parts": [
{
"number": 123,
"chunk_start": 123,
"chunk_end": 123,
"checksum_sha256_base64": "<string>"
}
]
},
"service": "<string>",
"organization_id": "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
"checksum_sha256_base64": "<string>",
"version": "<string>"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
mime_type: '<string>',
size: 123,
upload: {
parts: [
{
number: 123,
chunk_start: 123,
chunk_end: 123,
checksum_sha256_base64: '<string>'
}
]
},
service: '<string>',
organization_id: '1dbfc517-0bbf-4301-9ba8-555ca42b9737',
checksum_sha256_base64: '<string>',
version: '<string>'
})
};
fetch('https://api.polar.sh/v1/files/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.polar.sh/v1/files/")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"mime_type\": \"<string>\",\n \"size\": 123,\n \"upload\": {\n \"parts\": [\n {\n \"number\": 123,\n \"chunk_start\": 123,\n \"chunk_end\": 123,\n \"checksum_sha256_base64\": \"<string>\"\n }\n ]\n },\n \"service\": \"<string>\",\n \"organization_id\": \"1dbfc517-0bbf-4301-9ba8-555ca42b9737\",\n \"checksum_sha256_base64\": \"<string>\",\n \"version\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.polar.sh/v1/files/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"mime_type\": \"<string>\",\n \"size\": 123,\n \"upload\": {\n \"parts\": [\n {\n \"number\": 123,\n \"chunk_start\": 123,\n \"chunk_end\": 123,\n \"checksum_sha256_base64\": \"<string>\"\n }\n ]\n },\n \"service\": \"<string>\",\n \"organization_id\": \"1dbfc517-0bbf-4301-9ba8-555ca42b9737\",\n \"checksum_sha256_base64\": \"<string>\",\n \"version\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"organization_id": "<string>",
"name": "<string>",
"path": "<string>",
"mime_type": "<string>",
"size": 123,
"storage_version": "<string>",
"checksum_etag": "<string>",
"checksum_sha256_base64": "<string>",
"checksum_sha256_hex": "<string>",
"last_modified_at": "2023-11-07T05:31:56Z",
"upload": {
"id": "<string>",
"path": "<string>",
"parts": [
{
"number": 123,
"chunk_start": 123,
"chunk_end": 123,
"url": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"checksum_sha256_base64": "<string>",
"headers": {}
}
]
},
"version": "<string>",
"size_readable": "<string>",
"is_uploaded": false
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}Authorizations
You can generate an Organization Access Token from your organization's settings.
Body
application/json
- DownloadableFileCreate
- ProductMediaFileCreate
- OrganizationAvatarFileCreate
Schema to create a file to be associated with the downloadables benefit.
Show child attributes
Show child attributes
Allowed value:
"downloadable"The organization ID.
Example:
"1dbfc517-0bbf-4301-9ba8-555ca42b9737"
Response
File created.
The ID of the object.
Show child attributes
Show child attributes
Available options:
downloadable, product_media, organization_avatar Was this page helpful?
⌘I
Go (SDK)
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
}
}from polar_sdk import Polar
with Polar(
access_token="<YOUR_BEARER_TOKEN_HERE>",
) as polar:
res = polar.files.create(request={
"name": "<value>",
"mime_type": "<value>",
"size": 612128,
"upload": {
"parts": [],
},
"service": "downloadable",
})
# Handle response
print(res)import { Polar } from "@polar-sh/sdk";
const polar = new Polar({
accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});
async function run() {
const result = await polar.files.create({
organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
name: "<value>",
mimeType: "<value>",
size: 612128,
upload: {
parts: [],
},
service: "downloadable",
});
console.log(result);
}
run();declare(strict_types=1);
require 'vendor/autoload.php';
use Polar;
use Polar\Models\Components;
$sdk = Polar\Polar::builder()
->setSecurity(
'<YOUR_BEARER_TOKEN_HERE>'
)
->build();
$request = new Components\DownloadableFileCreate(
organizationId: '1dbfc517-0bbf-4301-9ba8-555ca42b9737',
name: '<value>',
mimeType: '<value>',
size: 612128,
upload: new Components\S3FileCreateMultipart(
parts: [],
),
);
$response = $sdk->files->create(
request: $request
);
if ($response->fileUpload !== null) {
// handle response
}curl --request POST \
--url https://api.polar.sh/v1/files/ \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "<string>",
"mime_type": "<string>",
"size": 123,
"upload": {
"parts": [
{
"number": 123,
"chunk_start": 123,
"chunk_end": 123,
"checksum_sha256_base64": "<string>"
}
]
},
"service": "<string>",
"organization_id": "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
"checksum_sha256_base64": "<string>",
"version": "<string>"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: '<string>',
mime_type: '<string>',
size: 123,
upload: {
parts: [
{
number: 123,
chunk_start: 123,
chunk_end: 123,
checksum_sha256_base64: '<string>'
}
]
},
service: '<string>',
organization_id: '1dbfc517-0bbf-4301-9ba8-555ca42b9737',
checksum_sha256_base64: '<string>',
version: '<string>'
})
};
fetch('https://api.polar.sh/v1/files/', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://api.polar.sh/v1/files/")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"<string>\",\n \"mime_type\": \"<string>\",\n \"size\": 123,\n \"upload\": {\n \"parts\": [\n {\n \"number\": 123,\n \"chunk_start\": 123,\n \"chunk_end\": 123,\n \"checksum_sha256_base64\": \"<string>\"\n }\n ]\n },\n \"service\": \"<string>\",\n \"organization_id\": \"1dbfc517-0bbf-4301-9ba8-555ca42b9737\",\n \"checksum_sha256_base64\": \"<string>\",\n \"version\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.polar.sh/v1/files/")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"<string>\",\n \"mime_type\": \"<string>\",\n \"size\": 123,\n \"upload\": {\n \"parts\": [\n {\n \"number\": 123,\n \"chunk_start\": 123,\n \"chunk_end\": 123,\n \"checksum_sha256_base64\": \"<string>\"\n }\n ]\n },\n \"service\": \"<string>\",\n \"organization_id\": \"1dbfc517-0bbf-4301-9ba8-555ca42b9737\",\n \"checksum_sha256_base64\": \"<string>\",\n \"version\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"organization_id": "<string>",
"name": "<string>",
"path": "<string>",
"mime_type": "<string>",
"size": 123,
"storage_version": "<string>",
"checksum_etag": "<string>",
"checksum_sha256_base64": "<string>",
"checksum_sha256_hex": "<string>",
"last_modified_at": "2023-11-07T05:31:56Z",
"upload": {
"id": "<string>",
"path": "<string>",
"parts": [
{
"number": 123,
"chunk_start": 123,
"chunk_end": 123,
"url": "<string>",
"expires_at": "2023-11-07T05:31:56Z",
"checksum_sha256_base64": "<string>",
"headers": {}
}
]
},
"version": "<string>",
"size_readable": "<string>",
"is_uploaded": false
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}
