# gdrive-file-info

> Fetch file information for publicly shared Google Drive items.

Latest version **1.2.0** (published 2019-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install gdrive-file-info
pnpm add gdrive-file-info
yarn add gdrive-file-info
bun add gdrive-file-info
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2019-03-20 |
| First published | 2018-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Dario Vladovic |
| Maintainers | vladimyr |
| Keywords | google-drive, file-info, sharing, direct-link |

## Links

- npm: https://www.npmjs.com/package/gdrive-file-info
- Repository: https://github.com/vladimyr/gdrive-file-info
- Issues: https://github.com/vladimyr/gdrive-file-info/issues
- npm.io page: https://npm.io/package/gdrive-file-info

## Dependencies (1)

- [got](https://npm.io/package/got.md) ^9.5.0

## Recent versions

- 1.2.0 (latest) — 2019-03-20
- 1.1.0 — 2019-01-21
- 1.0.2 — 2019-01-12
- 1.0.1 — 2018-12-20
- 1.0.0 — 2018-12-20

## README

# gdrive-file-info

[![build status](https://badgen.net/travis/vladimyr/gdrive-file-info)](https://travis-ci.com/vladimyr/gdrive-file-info/) [![install size](https://badgen.net/packagephobia/install/gdrive-file-info)](https://packagephobia.now.sh/result?p=gdrive-file-info) [![npm package version](https://badgen.net/npm/v/gdrive-file-info)](https://npm.im/gdrive-file-info) [![github license](https://badgen.net/github/license/vladimyr/gdrive-file-info)](https://github.com/vladimyr/gdrive-file-info/blob/master/LICENSE) [![js semistandard style](https://badgen.net/badge/code%20style/semistandard/pink)](https://github.com/Flet/semistandard)

> Fetch file information for publicly shared Google Drive items.

## Instalation

    $ npm install gdrive-file-info

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [GDriveError](#gdriveerror)
    -   [Properties](#properties)
-   [FileInfo](#fileinfo)
    -   [Properties](#properties-1)
-   [Dimensions](#dimensions)
    -   [Properties](#properties-2)
-   [fetchInfo](#fetchinfo)
    -   [Parameters](#parameters)
    -   [Examples](#examples)
-   [getItemId](#getitemid)
    -   [Parameters](#parameters-1)
    -   [Examples](#examples-1)

### GDriveError

**Extends Error**

Custom error class used for wrapping HTTP errors

#### Properties

-   `reason` **[Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error)** original HTTP error

### FileInfo

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

#### Properties

-   `disposition` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Google Drive scan status
-   `fileName` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** item filename
-   `downloadUrl` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** generated direct download url
-   `scanResult` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Google Drive scan result
-   `sizeBytes` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** file size
-   `thumbnailUrl` **function ([Dimensions](#dimensions)): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** 

### Dimensions

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

#### Properties

-   `width` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** 
-   `height` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** 

### fetchInfo

Fetch file info for given item id

#### Parameters

-   `input` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Google Drive item view/open url or item id

#### Examples

```javascript
// fetch public video info
const info = await fetchInfo('https://drive.google.com/open?id=1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD');
console.log(info.downloadUrl);
//=> https://doc-00-6c-docs.googleusercontent.com/docs/securesc/…/1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD

// generate poster url
const thumbnailUrl = await info.thumbnailUrl({ width: 1280, height: 720 });
//=> https://lh3.googleusercontent.com/9CwZKAQJ2U0CjjcIt5iZCqd-w-0d5ClJuYHVlS4olLrzt6AZr9rCdDu4jVzrz9b-tK5aswE4vdA=w1280-h720-p
```

-   Throws **[GDriveError](#gdriveerror)** throws on querying missing/private items
-   Throws **[TypeError](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypeError)** throws on invalid ID provided

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[FileInfo](#fileinfo)>** item info

### getItemId

Extract item id from Google Drive shareable link

#### Parameters

-   `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Google Drive item view/open url

#### Examples

```javascript
// with _open_ link
const id = getItemId('https://drive.google.com/open?id=1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD');
//=> 1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD

// with _view_ link
const id = getItemId('https://drive.google.com/file/d/1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD/view?usp=sharing');
//=> 1ObJEVgO6Y4cFjfxszUb1LhdyeKrq_wGD

// with _edit_ link
const id = getItemId('https://docs.google.com/document/d/1OHA32KWVF21s0ahDMr8Qv2oDamQuLNoYkTN0N_RuRXA/edit');
// => 1OHA32KWVF21s0ahDMr8Qv2oDamQuLNoYkTN0N_RuRXA
```

Returns **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** item id

---
_Source: https://npm.io/package/gdrive-file-info · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
