Upload the image to a server
Using the store
property on the createDefaultImageWriter
function we can automatically upload images to a server or other location after processing.
By default the image will be posted as a form field with the name "dest"
.
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="./pintura.css" />
</head>
<style>
.pintura-editor {
height: 600px;
}
</style>
<div id="editor"></div>
<script type="module">
import { appendDefaultEditor } from './pintura.js';
const editor = appendDefaultEditor('#editor', {
src: 'image.jpeg',
imageWriter: {
// We instruct the editor to post the file object to the server
store: './upload/',
},
});
</script>
import '@pqina/pintura/pintura.css';
import './App.css';
import { PinturaEditor } from '@pqina/react-pintura';
import { getEditorDefaults } from '@pqina/pintura';
const editorDefaults = getEditorDefaults({
imageWriter: {
// We instruct the editor to post the file object to the server
store: './upload/',
},
});
function App() {
return (
<div className="App">
<PinturaEditor {...editorDefaults} src={'image.jpeg'} />
</div>
);
}
export default App;
.pintura-editor {
height: 600px;
}
<template>
<div>
<PinturaEditor v-bind="editorDefaults" src="image.jpeg" />
</div>
</template>
<script>
import { PinturaEditor } from '@pqina/vue-pintura';
import { getEditorDefaults } from '@pqina/pintura';
export default {
name: 'App',
components: {
PinturaEditor,
},
data() {
return {
editorDefaults: getEditorDefaults({
imageWriter: {
// We instruct the editor to post the file object to the server
store: './upload/',
},
}),
};
},
methods: {},
};
</script>
<style>
@import '@pqina/pintura/pintura.css';
.pintura-editor {
height: 600px;
}
</style>
<script>
import { PinturaEditor } from '@pqina/svelte-pintura';
import { getEditorDefaults } from '@pqina/pintura';
import '@pqina/pintura/pintura.css';
let editorDefaults = getEditorDefaults({
imageWriter: {
// We instruct the editor to post the file object to the server
store: './upload/',
},
});
</script>
<div>
<PinturaEditor {...editorDefaults} src={'image.jpeg'} />
</div>
<style>
div :global(.pintura-editor) {
height: 600px;
}
</style>
import { Component } from '@angular/core';
import { getEditorDefaults } from '@pqina/pintura';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
editorDefaults: any = getEditorDefaults({
imageWriter: {
// We instruct the editor to post the file object to the server
store: './upload/',
},
});
}
<pintura-editor [options]="editorDefaults" src="image.jpeg"></pintura-editor>
::ng-deep .pintura-editor {
height: 600px;
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AngularPinturaModule } from '@pqina/angular-pintura';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AngularPinturaModule],
exports: [AppComponent],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="./pintura/pintura.css" />
</head>
<script src="./jquery.js"></script>
<script src="./jquery-pintura/useEditorWithJQuery-iife.js"></script>
<script src="./pintura/pintura-iife.js"></script>
<style>
.pintura-editor {
height: 600px;
}
</style>
<div id="editor"></div>
<script>
useEditorWithJQuery(jQuery, pintura);
$(function () {
var editor = $('#editor').pinturaDefault({
src: 'image.jpeg',
imageWriter: {
// We instruct the editor to post the file object to the server
store: './upload/',
},
});
});
</script>
If we want to change the name of the field we can set the store
property to an object.
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="./pintura.css" />
</head>
<style>
.pintura-editor {
height: 600px;
}
</style>
<div id="editor"></div>
<script type="module">
import { appendDefaultEditor } from './pintura.js';
const editor = appendDefaultEditor('#editor', {
src: 'image.jpeg',
imageWriter: {
store: {
// Where to post the files to
url: './upload/',
// Which fields to post
dataset: (state) => [
['imageFile', state.dest, state.dest.name],
],
},
},
});
</script>
import '@pqina/pintura/pintura.css';
import './App.css';
import { PinturaEditor } from '@pqina/react-pintura';
import { getEditorDefaults } from '@pqina/pintura';
const editorDefaults = getEditorDefaults({
imageWriter: {
store: {
// Where to post the files to
url: './upload/',
// Which fields to post
dataset: (state) => [['imageFile', state.dest, state.dest.name]],
},
},
});
function App() {
return (
<div className="App">
<PinturaEditor {...editorDefaults} src={'image.jpeg'} />
</div>
);
}
export default App;
.pintura-editor {
height: 600px;
}
<template>
<div>
<PinturaEditor v-bind="editorDefaults" src="image.jpeg" />
</div>
</template>
<script>
import { PinturaEditor } from '@pqina/vue-pintura';
import { getEditorDefaults } from '@pqina/pintura';
export default {
name: 'App',
components: {
PinturaEditor,
},
data() {
return {
editorDefaults: getEditorDefaults({
imageWriter: {
store: {
// Where to post the files to
url: './upload/',
// Which fields to post
dataset: (state) => [
['imageFile', state.dest, state.dest.name],
],
},
},
}),
};
},
methods: {},
};
</script>
<style>
@import '@pqina/pintura/pintura.css';
.pintura-editor {
height: 600px;
}
</style>
<script>
import { PinturaEditor } from '@pqina/svelte-pintura';
import { getEditorDefaults } from '@pqina/pintura';
import '@pqina/pintura/pintura.css';
let editorDefaults = getEditorDefaults({
imageWriter: {
store: {
// Where to post the files to
url: './upload/',
// Which fields to post
dataset: (state) => [
['imageFile', state.dest, state.dest.name],
],
},
},
});
</script>
<div>
<PinturaEditor {...editorDefaults} src={'image.jpeg'} />
</div>
<style>
div :global(.pintura-editor) {
height: 600px;
}
</style>
import { Component } from '@angular/core';
import { getEditorDefaults } from '@pqina/pintura';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
editorDefaults: any = getEditorDefaults({
imageWriter: {
store: {
// Where to post the files to
url: './upload/',
// Which fields to post
dataset: (state) => [
['imageFile', state.dest, state.dest.name],
],
},
},
});
}
<pintura-editor [options]="editorDefaults" src="image.jpeg"></pintura-editor>
::ng-deep .pintura-editor {
height: 600px;
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AngularPinturaModule } from '@pqina/angular-pintura';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AngularPinturaModule],
exports: [AppComponent],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="./pintura/pintura.css" />
</head>
<script src="./jquery.js"></script>
<script src="./jquery-pintura/useEditorWithJQuery-iife.js"></script>
<script src="./pintura/pintura-iife.js"></script>
<style>
.pintura-editor {
height: 600px;
}
</style>
<div id="editor"></div>
<script>
useEditorWithJQuery(jQuery, pintura);
$(function () {
var editor = $('#editor').pinturaDefault({
src: 'image.jpeg',
imageWriter: {
store: {
// Where to post the files to
url: './upload/',
// Which fields to post
dataset: (state) => [
['imageFile', state.dest, state.dest.name],
],
},
},
});
});
</script>
The store
property can also be set to a function in which case we gain full control over where and how to store the output image. An example of this can be found in store documentation entry.
To handle multiple images it's best to combine Pintura Image Editor with a file upload library like FilePond, Dropzone, Uppy, or jQuery File Upload.
See the installation libraries page for a list of file upload library integration examples.