Save dataURL as image with Filepicker.io exportWidget - filepicker.io

It seems like using the Filepicker.io javascript API you can save a dataURL, but I'm wondering if it's possible to save a dataURL mime-typed as "image/png" with the Filepicker.io export widget? When I attempt this I get an exception: Invalid file to export. I read that using the JS API you need to strip the "data:image/png;base64," prefix, however that seems to give the same exception.
I'm stripping this off like so:
myCanvasImage = canvas.toDataURL('image/png').split(',',2)[1];
But this seems to throw the same error. Any idea if this is possible with the Filepicker widget?

You can use it inside filepicker store function. It will deal with base64 decoding.
var dataURL = $('#canvasElement')[0].toDataURL().split(',', 2)[1];
filepicker.store(
dataURL,
{
base64decode: true,
mimetype: 'image/jpeg'
},
function(InkBlob){
filepicker.exportFile(
InkBlob,
{suggestedFilename:"yourFileName"},
function(InkBlob){
console.log(InkBlob);
},
function(FPError) {
console.log(FPError.toString());
}
);
},
function(FPError) {
console.log(FPError.toString());
}
);

Related

File upload works in Thunder Client and Chrome, but not Dio or MultipartRequest

I'm trying to create a flutter app that will allow a user to upload an image and a brief description of said image, and if I test my server code with either Thunder Client or Chrome, it works great, but if I try either the MultipartRequest or Dio from a Flutter app, the image seems to be included in the list of text fields, and the "files" part of the form object is empty. This happens no matter whether I try to upload an image or a small text document. Here is my Flutter code:
ElevatedButton(
child: const Text("Submit Report"),
onPressed: () async {
var dio = Dio();
var formData = FormData.fromMap({
"description": "This is a description",
"location": "This is a location",
"image": MultipartFile.fromBytes(
utf8.encode("hello, world"),
filename: "hello.txt",
contentType: MediaType("text", "plain")),
});
var response = await dio.post(
"${dotenv.env['SUPABASE_FUNCTIONS_URL']!}/hello-world",
data: formData,
);
debugPrint("***${response.statusCode}***");
},
)
If I debug and look at the Network tab in Dart's DevTools, I can see the request headers are set like they should be (Content-Type is multipart/form-data and a boundary is set). My server is just a small Deno function using the multiParser library running on Supabase:
serve(async (req) => {
const form = await multiParser(req);
console.log(form);
return new Response(
JSON.stringify(form),
{ headers: { "Content-Type": "application/json" } },
);
})
If I look at the invocation logs on Supabase, the requests coming from Thunder Client and Chrome look fine; the fields and files are populated the way they should be. Meanwhile, coming from Flutter (Dio and MultipartRequest yield the same result), the console.log(form) from above looks like this:
{
fields: {
description: "This is a description",
location: "This is a location",
'image"; filename="hello.txt"\r\ncontent-type: text/plai': "hello, world"
},
files: {}
}
I have tried manually setting various headers (like Content-Type), tried both the MultipartRequest and Dio approaches, and tried manually tweaking the file being uploaded (content type as well as file body). Also tried both running in an emulator as well as on a real Android phone. The result is always the same.
Used Oak's multipart/form-data parser instead, and it works with everything. Seems to be some sort of incompatibility between MultipartRequest/Dio and multiParser. Thanks to #pskink for troubleshooting with me.

Uploading a file to server using http MultiPartRequest

Hello to everyone i hope you all good.
Im trying to upload a image to a server im using this:
But it dosent work. So please help me, i would really appreciate it.
Future<int> uploadFile(imageFile) async {
try {
var request = http.MultipartRequest(
'POST',
Uri.parse('http://10.0.2.2:8000/objects/'),
);
Map<String, String> headers = {"Content-type": "multipart/form-data"};
request.files.add(
http.MultipartFile(
'file',
imageFile.readAsBytes().asStream(),
imageFile.lengthSync(),
contentType: MediaType(
'image',
'jpeg',
),
),
);
request.headers.addAll(headers);
request.fields.addAll({
"app_label": "files",
"app_model": "file",
});
print("request: " + request.toString());
var res = await request.send();
print("This is response:" + res.toString());
return res.statusCode;
} catch (err) {
print(err);
return 502;
}
}
Response from the server and vscode:
https://ibb.co/2SMTBxJ
You can check the project here:
https://github.com/bRUNS123/hydra
Also if someone know how to put the image without crop like the "finished" file.
I the app you can take an image from the gallery or camera, then you have a preview and you can send or save to the gallery. But i created an option to avoid the crop image, but when i try to pass the information to not crop, nothing happen.
Also i wanna know if i can put all my void functions in a separated file.
Hope you have a great day!!

Express [413 too large] with QuillJS image

I am trying to use QuillJS to let the user write a rich text, and then store it as JSON to display later on. There are 2 of these rich text areas in a single form, and may include images. QuillJS encodes images as base64 strings, and my POST request results in 413 by Express.
I have tried to change the limits by adding express json parameters, even trying extreme numbers.
// app.js
//----------------------------------------------------
// Middlewares
//----------------------------------------------------
app.use(express.json({limit: '2000mb'}));
app.use(express.urlencoded({extended: true, limit:'2000mb'}));
Even this did not help and I think it is not logical to let these parameters with such values.
I tried with json and urlencoded enctypes. When I tried to post with multipart/form, req.body was empty.
// My html page (pugJS)
form(enctype='application/x-www-form-urlencoded', action='/editor/page',
method='POST', onsubmit='return addContent()')
.form-control
label Content-1
div#toolbar
div#editor
input#content(name='content', type='text', hidden)
addContent() function that runs before form submit simply changes input#content's value with JSON.stringify(#editor.getContents())
I want to be able to store two quill content in a single database row, to display later.
A better approach to this would be to overwrite the image upload function and then save the image in Amazon S3 or some cloud server. Then you paste it inside the editor as <img src="http://uploaded-image-url"> This would solve your problem of maximum memory issue.
I fixed my problem few hours before #argo mentioned and I did it that way. So I wanted to post little bit of detail to the solution. I have been also guided by a github issue but can't seem to find the link again, in case I find it I will edit the post and add it.
// Quill - EN content
var quillEn = new Quill('#editor-en', {
modules: {
toolbar: toolbarOptions
},
theme: 'snow'
});
// set custom image handler
quillEn.getModule('toolbar').addHandler('image', () => {
selectLocalImage(quillEn);
});
// create fake input to upload image to quill
function selectLocalImage(editor) {
const input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('accept', 'image/png, image/jpeg')
input.click();
// Listen upload local image and save to server
input.onchange = () => {
const file = input.files[0];
saveImageToServer(editor, file);
};
}
// upload image to server
function saveImageToServer(editor, file) {
const fd = new FormData();
fd.append('image', file);
const xhr = new XMLHttpRequest();
xhr.open('POST', '/api/page/upload_image', true);
xhr.onload = () => {
if (xhr.status === 200) {
// this is callback data: url
const url = JSON.parse(xhr.responseText).data;
insertToEditor(editor, url);
}
};
xhr.send(fd);
}
// manipulate quill to replace b64 image with uploaded image
function insertToEditor(editor, url) {
// push image url to rich editor.
const range = editor.getSelection();
editor.insertEmbed(range.index, 'image', url.toString());
}
In the backend where you POST image, you must return json as { data: FullUrlToImg } with 200 response, if you want to change your status to 201 or something else, don't forget to update it in saveImageToServer function.
So to summarize, you set custom image handler for your quill editor, you post the image to server as soon as user chooses to insert, then you replace the URL with your uploaded image in the editor.
Thanks.

perl redirect url with the paramter using $Std->url()

I am new to Perl/Mason.
My url is https://www.myurl.com/myPar/2016image which will return a png image.
In this url, myPar is the parameter (equals to $orderViewHelper->{orderId}).
I have created an orderViewHelper which will hold myImage object so I can access it in other classes. Is there a way that I can use $Std->url() to get the image and put it into myImage?
$orderViewHelper->{myImage} = $Std->url(
'https://www.myurl.com/$orderViewHelper->{orderId}/2016image',
{ absolute =>1 }
);
I think this will work:
$orderViewHelper->{myImage} = $Std->url("https://www.myurl.com/$orderViewHelper->{orderId}/2016image", { absolute =>1 });

Extjs file upload progress

I have seen form file upload example in ExtJS4 and i need customize progress of the file upload.
I see waitMsg config property, but i don't want use that and i don't want use extjs 3rd party plugins.
So, how i can get simply current upload progress from upload form in extjs?
The waitMsg uses a message box with an infinitely auto-updating progress bar. So you can't just create a progressbar that displays the current upload.
You could create your own Ext.ProgressBar and estimate the upload time and when its done you set it to the max value. But I guess you don't want that.
To answer your question: You cannot simply track the current upload progress.
If you really need this user experience you can try a 3rd party component.
To quote the docs:
File uploads are not performed using normal "Ajax" techniques, that is
they are not performed using XMLHttpRequests. Instead the form is
submitted in the standard manner with the DOM element
temporarily modified to have its target set to refer to a dynamically
generated, hidden which is inserted into the document but
removed after the return data has been gathered.
To show real progress you can use onprogress callback of XMLHttpRequest:
Ext.override(Ext.data.request.Ajax, {
openRequest: function (options) {
var xhr = this.callParent(arguments);
if (options.progress) {
xhr.upload.onprogress = options.progress;
}
return xhr;
}
});
Then use like here:
Ext.Ajax.request({
url: '/upload/files',
rawData: data,
headers: { 'Content-Type': null }, //to use content type of FormData
progress: function (e) {
console.log('progress', e.loaded / e.total);
}
});
See online demo here.
buttons: [{
text: 'Upload',
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
url: '/upload/file',
waitMsg: 'Uploading your file...',
success: function (f, a) {
var result = a.result,
data = result.data,
name = data.name,
size = data.size,
message = Ext.String.format('<b>Message:</b> {0}<br>' +
'<b>FileName:</b> {1}<br>' +
'<b>FileSize:</b> {2} bytes',
result.msg, name, size);
Ext.Msg.alert('Success', message);
},
failure: function (f, a) {
Ext.Msg.alert('Failure', a.result.msg);
}
});
}
}
}]
Live demo with progress window is here