Upload a file to Cloud Storage This REST API uploads a file to Cloud Storage.
Upload a file to Cloud Storage REST API
Server
Method
Endpoint
https://api.aspose.cloud/v4.0
PUT
/words/storage/file/{path}
, where:
path
(required) — path where to upload including filename and extension e.g. /file.ext or /Folder 1/file.ext
If the content is multipart and path does not contains the file name it tries to get them from filename parameter
from Content-Disposition header.
You can use the following parameters in a REST request:
Parameter Name
Data Type
Required/Optional
Description
storageName
string
Optional
Storage name
Use $multipart/form-data
request to combine one or more properties into a single body:
Property Name
Data Type
Required/Optional
Description
fileContent
string(binary)
Required
File to upload
Note : to access this REST API, you need to register and get personal credentials. Use the ‘
Quick Start ’ guide to go through the procedure in a couple of minutes.
Upload a file to Cloud Storage usage examples
Let’s look at practical examples of using the web service. You can do this both with cURL and Postman utilities, and from your code in various programming languages: Python, Java, JavaScript, C#, PHP, C++, Go, Ruby, Swift, Dart.
How to upload a file to Cloud Storage with cURL or Postman
One of the easiest and fastest ways to call a REST API is to use cURL or Postman:
cURL Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -v "https://api.aspose.cloud/v4.0/words/storage/file/Sample.docx" \
-X PUT \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer ####################" \
-F FileContent="@Sample.docx"
To get a JWT token use these instructions
Postman Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{
"info": {
"name": "UploadFile",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "clientSecret",
"value": "{{CLIENT_SECRET}}",
"type": "string"
},
{
"key": "clientId",
"value": "{{CLIENT_ID}}",
"type": "string"
},
{
"key": "addTokenTo",
"value": "header",
"type": "string"
},
{
"key": "client_authentication",
"value": "body",
"type": "string"
},
{
"key": "accessTokenUrl",
"value": "https://api.aspose.cloud/connect/token",
"type": "string"
},
{
"key": "grant_type",
"value": "client_credentials",
"type": "string"
},
{
"key": "tokenName",
"value": "Access Token",
"type": "string"
}
]
},
"item": [
{
"name": "uploadRequest",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "FileContent",
"type": "file",
"src": "Sample.docx"
}
]
},
"url": {
"raw": "https://api.aspose.cloud/v4.0/words/storage/file/Sample.docx",
"protocol": "https",
"host": [
"api",
"aspose",
"cloud"
],
"path": [
"v4.0",
"words",
"storage",
"file",
"Sample.docx"
],
"query": [
]
}
},
"response": []
}
],
"variable": [
]
}
To get a JWT token use these instructions
How to upload a file to Cloud Storage in Python, Java, C#, C++, JavaScript and other programming languages
Using SDK is the quickest way to speed up the development. Please take a look at the provided code examples to quickly call this web service from your favourite programming language:
Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os
import asposewordscloud
import asposewordscloud.models.requests
from asposewordscloud.rest import ApiException
from shutil import copyfile
words_api = WordsApi(client_id = '####-####-####-####-####', client_secret = '##################')
request_file_content = open('Sample.docx', 'rb')
upload_request = asposewordscloud.models.requests.UploadFileRequest(file_content=request_file_content, path='Sample.docx')
words_api.upload_file(upload_request)
Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.aspose.words.cloud.*;
import com.aspose.words.cloud.api.*;
import com.aspose.words.cloud.model.*;
import com.aspose.words.cloud.model.requests.*;
import com.aspose.words.cloud.model.responses.*;
import java.nio.file.Files;
import java.nio.file.Paths;
ApiClient apiClient = new ApiClient(/*clientId*/ "####-####-####-####-####", /*clientSecret*/ "##################", null);
WordsApi wordsApi = new WordsApi(apiClient);
byte[] requestFileContent = Files.readAllBytes(Paths.get("Sample.docx").toAbsolutePath());
UploadFileRequest uploadRequest = new UploadFileRequest(requestFileContent, "Sample.docx", null);
wordsApi.uploadFile(uploadRequest);
Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from "fs";
const clientId = "####-####-####-####-####";
const secret = "##################";
const wordsApi = new WordsApi(clientId, secret);
const requestFileContent = fs.createReadStream("Sample.docx");
const uploadRequest = new model.UploadFileRequest({
fileContent: requestFileContent,
path: "Sample.docx"
});
wordsApi.uploadFile(uploadRequest)
.then((uploadRequestResult) => {
// tslint:disable-next-line:no-console
console.log("Result of uploadRequest: ", uploadRequestResult);
});
C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Aspose.Words.Cloud.Sdk;
using Aspose.Words.Cloud.Sdk.Model;
using Aspose.Words.Cloud.Sdk.Model.Requests;
var config = new Configuration { ClientId = "####-####-####-####-####", ClientSecret = "##################" };
var wordsApi = new WordsApi(config);
using var requestFileContent = File.OpenRead("Sample.docx");
var uploadRequest = new UploadFileRequest(requestFileContent, "Sample.docx");
await wordsApi.UploadFile(uploadRequest);
PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php
use Aspose\Words\WordsApi;
use Aspose\Words\Model\Requests\{UploadFileRequest};
$clientId = '####-####-####-####-####';
$secret = '##################';
$wordsApi = new WordsApi($clientId, $secret);
$requestFileContent = "Sample.docx";
$uploadRequest = new UploadFileRequest(
$requestFileContent, "Sample.docx", NULL);
$wordsApi->uploadFile($uploadRequest);
C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "aspose_words_cloud.h"
using namespace aspose::words::cloud;
auto config = std::make_shared<ApiConfiguration>(/*clientId*/ L"####-####-####-####-####", /*clientSecret*/ L"##################");
auto wordsApi = std::make_shared<WordsApi>(config);
auto requestFileContent = std::shared_ptr<std::istream>(new std::ifstream(std::filesystem::path(L"Sample.docx"), std::istream::binary));
std::shared_ptr<requests::UploadFileRequest> uploadRequest(
new requests::UploadFileRequest(
requestFileContent, std::make_shared<std::wstring>(L"Sample.docx")));
wordsApi->uploadFile(uploadRequest);
Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{
"ClientId" : " ####-####-####-####-####" ,
"ClientSecret" : " ##################" ,
"BaseUrl" : " https://api.aspose.cloud"
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import (
"os"
"github.com/aspose-words-cloud/aspose-words-cloud-go/dev/api/models")
config, _ := models.NewConfiguration("config.json")
wordsApi, ctx, _ := api.CreateWordsApi(config)
requestFileContent, _ := os.Open("Sample.docx")
uploadRequestOptions := map[string]interface{}{}
uploadRequest := &models.UploadFileRequest{
FileContent: requestFileContent,
Path: ToStringPointer("Sample.docx"),
Optionals: uploadRequestOptions,
}
_, _, _ = wordsApi.UploadFile(ctx, uploadRequest)
Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'aspose_words_cloud'
AsposeWordsCloud.configure do |config|
config.client_data['ClientId'] = '####-####-####-####-####'
config.client_data['ClientSecret'] = '##################'
end
@words_api = WordsAPI.new
request_file_content = File.open('Sample.docx')
upload_request = UploadFileRequest.new(file_content: request_file_content, path: 'Sample.docx')
@words_api.upload_file(upload_request)
Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AsposeWordsCloud
let config = Configuration(clientId: "####-####-####-####-####", clientSecret: "##################");
let api = try WordsAPI(configuration: config);
let requestFileContent = InputStream(url: URL(string: "Sample.docx"))!;
let uploadRequest = UploadFileRequest(fileContent: requestFileContent, path: "Sample.docx");
_ = try api.uploadFile(request: uploadRequest);
Dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io';
import 'package:aspose_words_cloud/aspose_words_cloud.dart';
final clientId = "####-####-####-####-####";
final clientSecret = "##################";
final config = Configuration(clientId, clientSecret);
final wordsApi = WordsApi(config);
final requestFileContent = (await File('Sample.docx').readAsBytes()).buffer.asByteData();
final uploadRequest = UploadFileRequest(requestFileContent, 'Sample.docx');
await wordsApi.uploadFile(uploadRequest);
See Also
GitHub repository — explore Aspose.Words Cloud SDK Family. These software libraries take care of all low-level document-processing details.