2021-04-21 03:14:43 +03:00
import * as React from "react" ;
import * as System from "~/components/system" ;
import CodeBlock from "~/components/system/CodeBlock" ;
2021-09-16 01:21:29 +03:00
const EXAMPLE _CODE _JS = ( key ) => ` const url = 'https://uploads.slate.host/api/v2/public';
2021-04-21 03:14:43 +03:00
let file = e . target . files [ 0 ] ;
let data = new FormData ( ) ;
data . append ( "data" , file ) ;
const response = await fetch ( url , {
method : 'POST' ,
headers : {
2021-07-31 01:00:06 +03:00
Authorization : '${key}' , // API key
2021-04-21 03:14:43 +03:00
} ,
body : data
} ) ; ` ;
const EXAMPLE _CODE _PY = ( key ) => ` import requests
2021-09-16 01:21:29 +03:00
url = "https://uploads.slate.host/api/v2/public"
2021-04-21 03:14:43 +03:00
files = {
"file" : open ( "example-file.txt" , "rb" )
}
headers = {
2021-07-31 01:00:06 +03:00
"Authorization" : "${key}" # API key
2021-04-21 03:14:43 +03:00
}
r = requests . post ( url , headers = headers , files = files ) ` ;
const SLATE _EXAMPLE _CODE _JS = (
key ,
slateId
2021-09-16 01:21:29 +03:00
) => ` const url = 'https://uploads.slate.host/api/v2/public/ ${ slateId } '; // collection ID
2021-04-21 03:14:43 +03:00
let file = e . target . files [ 0 ] ;
let data = new FormData ( ) ;
data . append ( "data" , file ) ;
const response = await fetch ( url , {
method : 'POST' ,
headers : {
2021-07-31 01:00:06 +03:00
Authorization : '${key}' , // API key
2021-04-21 03:14:43 +03:00
} ,
body : data
2021-07-31 01:00:06 +03:00
} ) ;
const json = await response . json ( ) ; ` ;
2021-04-21 03:14:43 +03:00
const SLATE _EXAMPLE _CODE _PY = ( key , slateId ) => ` import requests
2021-09-16 01:21:29 +03:00
url = "https://uploads.slate.host/api/v2/public/${slateId}" # collection ID
2021-04-21 03:14:43 +03:00
files = {
"file" : open ( "example-file.txt" , "rb" )
}
headers = {
2021-07-31 01:00:06 +03:00
"Authorization" : "${key}" # API key
2021-04-21 03:14:43 +03:00
}
r = requests . post ( url , headers = headers , files = files ) ` ;
export default class APIDocsUploadToSlate extends React . Component {
render ( ) {
let language = this . props . language ;
let key = this . props . APIKey ;
let slateId = this . props . slateId ;
let uploadCode = {
javascript : EXAMPLE _CODE _JS ( key ) ,
python : EXAMPLE _CODE _PY ( key ) ,
} ;
let slateUploadCode = {
javascript : SLATE _EXAMPLE _CODE _JS ( key , slateId ) ,
python : SLATE _EXAMPLE _CODE _PY ( key , slateId ) ,
} ;
return (
2021-08-02 05:56:55 +03:00
< div css = { this . props . cssValue } style = { this . props . style } >
2021-04-21 03:14:43 +03:00
< System . DescriptionGroup
2021-08-02 05:56:55 +03:00
style = { { maxWidth : 640 } }
label = "Upload File"
2021-04-21 03:14:43 +03:00
description = {
2021-04-23 08:18:46 +03:00
"This API endpoint allows you to upload file(s) to your collection. This uses our data transfer microservice to interact with Textile Buckets and upload data to the IPFS/Filecoin network."
2021-04-21 03:14:43 +03:00
}
/ >
< CodeBlock
children = { uploadCode }
style = { { maxWidth : "820px" } }
language = { language }
2021-07-13 22:08:56 +03:00
title = "Upload file"
2021-04-21 03:14:43 +03:00
multiLang = "true"
onLanguageChange = { this . props . onLanguageChange }
/ >
< br / >
< CodeBlock
children = { slateUploadCode }
style = { { maxWidth : "820px" } }
language = { language }
2021-07-13 22:08:56 +03:00
title = "Upload file to collection"
2021-04-21 03:14:43 +03:00
multiLang = "true"
onLanguageChange = { this . props . onLanguageChange }
/ >
2021-08-02 05:56:55 +03:00
< / d i v >
2021-04-21 03:14:43 +03:00
) ;
}
}