question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How i can send files from camera with CameraResultType.Uri?

See original GitHub issue
import { Plugins, CameraResultType } from '@capacitor/core';

const { Camera } = Plugins;

async takePicture() {
  const image = await Camera.getPhoto({
    quality: 90,
    allowEditing: true,
    resultType: CameraResultType.Uri
  });
 
  var imageUrl = image.webPath;
  imageElement.src = imageUrl;
}

How i can send form with a camera image file?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

33reactions
jcesarmobilecommented, Oct 24, 2018

Capacitor doesn’t provide a plugin or method for uploading files, you can use XHR or fetch to do so.

As example of how you can do it.

get the blob from the url:

let blob = await fetch(cameraResult.webPath).then(r => r.blob());

or get the blob from the base64:

let blob = b64toBlob(contents.data, "image/jpg", 512);

(google for b64toBlob method).

Once you have the blob, append it to FormData

let formData = new FormData();
formData.append("image", blob);

And upload it with XHR or fetch (example for XHR)

var oReq = new XMLHttpRequest();
oReq.open("POST", "https://yourserver.com/upload.php", true);
oReq.send(formData);
0reactions
ionitron-bot[bot]commented, Dec 1, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to upload an image coming from the Ionic's Camera to ...
1 Answer 1 · Thank you, I've seen your name quite some times while searching for a solution :). But is there a...
Read more >
The Ionic Image Guide with Capacitor (Capture, Store & Upload)
Capturing, storing and uploading image files with Ionic is a crucial ... To test the camera directly in our browser we can also...
Read more >
Camera Capacitor Plugin API
If using CameraResultType.Uri, the path will contain a full, platform-specific file URL that can be read later using the Filesystem API. 1.0.0.
Read more >
Using the Capacitor Filesystem API to Store Photos
In this tutorial, we will be covering how to use Capacitor to retrieve a photo from the user's camera or photo library, and...
Read more >
Taking Photos with the Camera - Ionic Framework
ionic g service services/photo. Copy. Open the new services/photo.service.ts file, and let's add the logic that will power the camera functionality.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found