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 to get the URI of the actual image for upload ?

See original GitHub issue

Hello gents!

I’m having issues understanding how to get the actual path of the files so I can upload them ? The array of images sent back from the picker is as follows:

data: {
    filename: "IMG_0005.JPG",
    height: 2002,
    isStored: true,
    playableDuration: 0,
    uri:"assets-library://asset/asset.JPG?id=ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED&ext=JPG",
    width: 3000
}

I understand I need to use “data.filename” … but what’s the absolute path ? Where or how to get it from ? Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Frexuzcommented, Oct 28, 2018

Ended up not using RNFetchBlob, but using Buffer instead.

This is what we currently use, in production:

import S3 from 'aws-sdk/clients/s3'
import { Buffer } from 'buffer'

export function uploadS3Base64Image (image, options) {
  const s3 = new S3({
    accessKeyId: s3options.accessKeyId,
    secretAccessKey: s3options.secretAccessKey,
    region: s3options.region
  })
  // get file name, if fileName is not exist, get fileName from filePath
  const fileName = image.filename || image.path.split('\\').pop().split('/').pop()
  // File structure helper
  const file = {
    name: `${uuid.v4()}-${fileName.toLowerCase()}`,
    type: image.mime
  }

  // Create buffer from base64 image
  let imageBuffer = Buffer.from(image.data.replace(/^data:image\/\w+;base64,/, ''), 'base64')

  // Create full file name
  let folderPath = _.compact(options.folderPath).join('/')
  let fileNameWithPath = `${folderPath}/${file.name}`

  // Upload params
  var params = {
    Bucket: s3options.bucket,
    Key: fileNameWithPath,
    Body: imageBuffer,
    'Content-Type': file.type,
    'Content-Length': imageBuffer.length,
    ACL: 'public-read'
  }

  // Setup progress handler, and then send the image
  s3.upload(params).on('httpUploadProgress', options.onProgress).send(options.onSendFinished)
}
1reaction
edicommented, Oct 8, 2017

Nevermind, fixed it 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

4 Ways to Get the URL for Pictures - wikiHow
1. Open the Google Image search page. Go to https://images.google.com/ in your computer's web browser. This will open the Google search page for...
Read more >
How to Get the URL for Pictures - YouTube
Suppose, you liked an online image and want to use the link of this image in your presentation. Then you need a URL...
Read more >
How do I get the URL of an image on my computer? - Quora
Type Control-O in the browser. In the file selector, navigate to your Desktop and double click on the file. It will open up...
Read more >
How to get image file uri from media entity id | Drupal.org
Once you have the media id, you can load, then get the image's fid and load that. use Drupal\media\Entity\Media; use Drupal\ ...
Read more >
How to Get the URL of Images You Upload in WordPress
You can get the attachment URL next to the 'Copy Link' option on the right column. We hope this article helped you to...
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