2021-03-24 07:10:26 +03:00
import * as React from "react" ;
import * as System from "~/components/system" ;
2021-04-20 04:07:19 +03:00
import CodeBlock from "~/components/system/CodeBlock" ;
2021-03-24 07:10:26 +03:00
2021-04-21 03:14:43 +03:00
const EXAMPLE _CODE _JS = ( key ) => ` const url = 'https://uploads.slate.host/api/public';
let file = e . target . files [ 0 ] ;
let data = new FormData ( ) ;
data . append ( "data" , file ) ;
const response = await fetch ( url , {
method : 'POST' ,
headers : {
Authorization : 'Basic ${key}' , // API key
} ,
body : data
} ) ; ` ;
const EXAMPLE _CODE _PY = ( key ) => ` import requests
url = "https://uploads.slate.host/api/public"
files = {
"file" : open ( "example-file.txt" , "rb" )
}
headers = {
"Authorization" : "Basic ${key}" # API key
}
r = requests . post ( url , headers = headers , files = files ) ` ;
const SLATE _EXAMPLE _CODE _JS = (
2021-03-24 07:10:26 +03:00
key ,
slateId
2021-04-23 07:18:02 +03:00
) => ` const url = 'https://uploads.slate.host/api/public/ ${ slateId } '; // collection ID
2021-03-24 07:10:26 +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-04-21 03:14:43 +03:00
Authorization : 'Basic ${key}' , // API key
2021-03-24 07:10:26 +03:00
} ,
body : data
2021-03-30 04:35:06 +03:00
} ) ; ` ;
2021-03-24 07:10:26 +03:00
2021-04-21 03:14:43 +03:00
const SLATE _EXAMPLE _CODE _PY = ( key , slateId ) => ` import requests
2021-04-05 23:21:23 +03:00
2021-04-23 07:18:02 +03:00
url = "https://uploads.slate.host/api/public/${slateId}" # collection ID
2021-04-21 03:14:43 +03:00
files = {
"file" : open ( "example-file.txt" , "rb" )
}
headers = {
"Authorization" : "Basic ${key}" # API key
}
2021-03-24 07:10:26 +03:00
2021-03-30 04:19:36 +03:00
r = requests . post ( url , headers = headers , files = files ) ` ;
2021-03-24 07:10:26 +03:00
2021-03-30 04:19:36 +03:00
export default class APIDocsUploadToSlate extends React . Component {
render ( ) {
let language = this . props . language ;
let key = this . props . APIKey ;
let slateId = this . props . slateId ;
2021-03-24 07:10:26 +03:00
2021-04-21 03:14:43 +03:00
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 ) ,
2021-03-30 04:19:36 +03:00
} ;
2021-03-24 07:10:26 +03:00
return (
< React . Fragment >
< System . DescriptionGroup
2021-03-30 04:19:36 +03:00
style = { { maxWidth : 640 , marginTop : 64 } }
2021-04-21 03:14:43 +03:00
label = "Upload"
2021-03-30 04:19:36 +03:00
description = {
2021-04-23 07:18:02 +03:00
"This API endpoint allows you to upload file(s) to your data. This uses our data transfer microservice to interact with Textile Buckets and upload data to the IPFS/Filecoin network."
2021-03-30 04:19:36 +03:00
}
2021-03-24 07:10:26 +03:00
/ >
< CodeBlock
2021-04-21 03:14:43 +03:00
children = { uploadCode }
style = { { maxWidth : "820px" } }
language = { language }
title = "Upload"
multiLang = "true"
onLanguageChange = { this . props . onLanguageChange }
/ >
< br / >
< CodeBlock
children = { slateUploadCode }
2021-03-30 04:19:36 +03:00
style = { { maxWidth : "820px" } }
2021-03-24 07:10:26 +03:00
language = { language }
2021-04-23 07:18:02 +03:00
title = "Upload"
2021-03-30 04:19:36 +03:00
multiLang = "true"
onLanguageChange = { this . props . onLanguageChange }
2021-03-24 07:10:26 +03:00
/ >
< / R e a c t . F r a g m e n t >
) ;
}
}