Docs | imagemash.io
DashboardSign up for Free
  • 🎉imagemash.io
  • 🚀Getting Started
    • Simple CDN Link Usage
  • 💽Sources
    • IM Cloud Storage
    • Image URL
    • Storage Providers
      • Amazon S3
      • Google Cloud
      • S3 Compatible Storage
    • Web Folder
  • 🖼️Image Transform
    • Transform Options
      • Quality
      • Width
      • Height
      • Scale
      • Crop
      • Gravity
      • Background
      • Border
      • Round
      • Output Format
      • Angle (Rotate)
      • Flip
      • Helpers
        • x, y
      • Filters
        • Tint
        • Flatten
        • Grayscale
        • Blur
        • Sharpen
        • Median
        • Threshold
        • Negative
    • Transform Cheat Sheet
    • Named Transforms
  • 🛠️API
    • API - Good to knows
    • API Methods
      • Account
        • Named Transforms
          • Get named transforms
          • Add named transform
          • Remove named transform
        • Image URL Restriction
          • Get keyword list
          • Add keyword to list
          • Remove keyword from list
          • Change keyword list usage
      • Storage
        • Upload file
        • Get and search files
        • Delete files
        • Add new tags to files
        • Set tags of files
        • Remove tags from files
        • Purge Cache
      • Optimize / Transform
  • ❓How it works?
    • Custom Domain
    • Bandwidth
    • Cloud Storage
    • Caching
    • Purge Cache
    • Limits
  • Contact Us
Powered by GitBook
On this page
  1. API
  2. API Methods
  3. Storage

Upload file

Upload file endpoint accepts multiple content-type;

  • "multipart/form-data" (for binary form-data file uploads, URL, base64)

  • "application/x-www-form-urlencoded" (URL, base64) (our usual request type)

  • "application/json" (URL,base64) (our usual request type)

Upload file to your IM Cloud Storage

POST https://api.imagemash.io/v1/storage/getFiles

Headers

Name
Type
Description

apikey*

String

Your API Key

Request Body

Name
Type
Description

file*

Multiple

Accepts 3 type;

binary: As form-data (buffer), base64: As base64 string, URL: URL of a file. Eg. https://examle.com/logo.png

fileName*

String

Name of your file with extension. Eg. logo.png , code.js, ...

parentPath

String

Parent path of your file. Leave empty or use / to upload file to home directory. Eg. /cars/small_cars

Default: /

{
    "name": "small_jeep.png",
    "type": "image",
    "filePath": "/cars/small_jeep.png",
    "folderPath": "/cars",
    "width": 8511,
    "height": 6323,
    "tags": [],
    "format": "png",
    "mime": "image/png",
    "size": 248971,
    "sizeHuman": "243,14 KB",
    "thumbnail": "https://demo.imagemash.io/cars/small_jeep.png?tr=imagemash,w_250,q_80,f_webp",
    "url": "https://demo.imagemash.io/cars/small_jeep?tr=imagemash",
    "createdAt": "2019-01-13T19:42:35.565Z",
    "updatedAt": "2019-01-13T19:42:35.565Z"
}
{
    msg: "error details"
    details: "..."
}   // Explanation of error
Unauthorized
{
    // Please contact support if you are getting this error constantly.
}

Example Codes - Binary(form-data)

curl --location --request POST 'https://api.imagemash.io/v1/storage/uploadFile' \
--header 'apikey: your_api_key' \
--form 'file=@"/C:/Users/Desktop/small_jeep.png"' \
--form 'parentPath="/cars"'
using System;
using RestSharp;
using System.Threading;
using System.Threading.Tasks;
namespace HelloWorldApplication {
  class HelloWorld {
    static async Task Main(string[] args) {
      var options = new RestClientOptions("https://api.imagemash.io")
      {
        MaxTimeout = -1,
      };
      var client = new RestClient(options);
      var request = new RestRequest("/v1/storage/uploadFile", Method.Post);
      request.AddHeader("apikey", "your_api_key");
      request.AlwaysMultipartFormData = true;
      request.AddFile("file", "/C:/Users/Desktop/small_jeep.png");
      request.AddParameter("parentPath", "/cars");
      RestResponse response = await client.ExecuteAsync(request);
      Console.WriteLine(response.Content);
    }
  }
}
import java.io.*;
import okhttp3.*;
public class main {
  public static void main(String []args) throws IOException{
    OkHttpClient client = new OkHttpClient().newBuilder()
      .build();
    MediaType mediaType = MediaType.parse("text/plain");
    RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
      .addFormDataPart("file","/C:/Users/Desktop/small_jeep.png",
        RequestBody.create(MediaType.parse("application/octet-stream"),
        new File("/C:/uploads/207f9fa039d3fa7eb77c247d0ef244a7")))
      .addFormDataPart("parentPath","/cars")
      .build();
    Request request = new Request.Builder()
      .url("https://api.imagemash.io/v1/storage/uploadFile")
      .method("POST", body)
      .addHeader("apikey", "your_api_key")
      .build();
    Response response = client.newCall(request).execute();
    System.out.println(response.body().string());
  }
}
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
var data = new FormData();
data.append('file', fs.createReadStream('/C:/Users/Desktop/small_jeep.png'));
data.append('parentPath', '/cars');

var config = {
  method: 'post',
maxBodyLength: Infinity,
  url: 'https://api.imagemash.io/v1/storage/uploadFile',
  headers: { 
    'apikey': 'your_api_key', 
    ...data.getHeaders()
  },
  maxRedirects: 0,
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});
import requests

url = "https://api.imagemash.io/v1/storage/uploadFile"

payload={'parentPath': '/cars'}
files=[
  ('file',('207f9fa039d3fa7eb77c247d0ef244a7',open('/C:/Users/Desktop/small_jeep.png','rb'),'application/octet-stream'))
]
headers = {
  'apikey': 'your_api_key'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
require "uri"
require "net/http"

url = URI("https://api.imagemash.io/v1/storage/uploadFile")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["apikey"] = "your_api_key"
form_data = [['file', File.open('/C:/Users/Desktop/small_jeep.png')],['parentPath', '/cars']]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body

Example Codes - URL/base64

curl --location --request POST 'https://api.imagemash.io/v1/storage/uploadFile' \
--header 'apikey: your_api_key' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'file=https://example.com/logo.png' \
--data-urlencode 'parentPath=/my_logos'
using System;
using RestSharp;
using System.Threading;
using System.Threading.Tasks;
namespace HelloWorldApplication {
  class HelloWorld {
    static async Task Main(string[] args) {
      var options = new RestClientOptions("https://api.imagemash.io")
      {
        MaxTimeout = -1,
      };
      var client = new RestClient(options);
      var request = new RestRequest("/v1/storage/uploadFile", Method.Post);
      request.AddHeader("apikey", "your_api_key");
      request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
      request.AddParameter("file", "https://example.com/logo.png");
      request.AddParameter("parentPath", "/my_logos");
      RestResponse response = await client.ExecuteAsync(request);
      Console.WriteLine(response.Content);
    }
  }
}
import java.io.*;
import okhttp3.*;
public class main {
  public static void main(String []args) throws IOException{
    OkHttpClient client = new OkHttpClient().newBuilder()
      .build();
    MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
    RequestBody body = RequestBody.create(mediaType, "file=https://example.com/logo.png&parentPath=/my_logos");
    Request request = new Request.Builder()
      .url("https://api.imagemash.io/v1/storage/uploadFile")
      .method("POST", body)
      .addHeader("apikey", "your_api_key")
      .addHeader("Content-Type", "application/x-www-form-urlencoded")
      .build();
    Response response = client.newCall(request).execute();
    System.out.println(response.body().string());
  }
}
var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
  'file': 'https://example.com/logo.png',
  'parentPath': '/my_logos' 
});
var config = {
  method: 'post',
maxBodyLength: Infinity,
  url: 'https://api.imagemash.io/v1/storage/uploadFile',
  headers: { 
    'apikey': 'your_api_key', 
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  maxRedirects: 0,
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});
import requests

url = "https://api.imagemash.io/v1/storage/uploadFile"

payload='file=https%3A%2F%2Fexample.com%2Flogo.png&parentPath=%2Fmy_logos'
headers = {
  'apikey': 'your_api_key',
  'Content-Type': 'application/x-www-form-urlencoded'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
require "uri"
require "net/http"

url = URI("https://api.imagemash.io/v1/storage/uploadFile")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["apikey"] = "your_api_key"
request["Content-Type"] = "application/x-www-form-urlencoded"
request.body = "file=https%3A%2F%2Fexample.com%2Flogo.png&parentPath=%2Fmy_logos"

response = https.request(request)
puts response.read_body
PreviousStorageNextGet and search files

Last updated 2 years ago

🛠️