Socket
Socket
Sign inDemoInstall

use-object-url

Package Overview
Dependencies
3
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-object-url

React Hook to create and revoke URL for any instance of `File`, `Blob` or `MediaSource`.


Version published
Maintainers
1
Weekly downloads
212
increased by13.37%

Weekly downloads

Readme

Source

useObjectURL

Build Status License Library minified size Library minified + gzipped size

React Hook that receives an instance of File, Blob or MediaSource and creates an URL representing it. It releases URL when component unmount or parameter changes.

import useObjectURL from 'use-object-url';

const DownloadFileLink = ({ file, filename }) => {
  const fileURL = useObjectURL(file);

  return (
    <a href={fileURL} target="_blank" download={filename}>
      Download
    </a>
  );
};

Installation

This library is published in the NPM registry and can be installed using any compatible package manager.

npm install use-object-url --save

# For Yarn, use the command below.
yarn add use-object-url

Installation from CDN

This module has an UMD bundle available through JSDelivr and Unpkg CDNs.

<!-- For UNPKG use the code below. -->
<script src="https://unpkg.com/use-object-url"></script>

<!-- For JSDelivr use the code below. -->
<script src="https://cdn.jsdelivr.net/npm/use-object-url"></script>

<script>
  function PreviewImage(props) {
    // UMD module is exposed through the "useObjectURL" function.
    var imageURL = useObjectURL(props.uploadedImage);

    return React.createElement('img', {
      src: imageURL,
      alt: 'Uploaded image',
      title: 'Preview of uploaded image.'
    });
  }
</script>

Documentation

Documentation generated from source files by Typedoc.

License

Released under MIT License.

Keywords

FAQs

Last updated on 01 Sep 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc