wrap-gyazo
v1.0.3
Published
Gyazo uploader made in TypeScript.
Downloads
3
Readme
wrap-gyazo
Gyazo API wrapper made in TypeScript.
*For now, only upload feature.
Installation
npm i wrap-gyazo
Register an application with Gyazo.
Authorize (Optional)
*If you want to get an access token for each user.
- Get client_id, secret_id and Callback URL in Gyazo Applications.
- Generate a link for approval.
import {GyazoAdmin} from 'wrap-gyazo';
const gyazoAdmin = new GyazoAdmin({
clientId:"***************",
redirectUri:"***************",
clientSecret:"***************"
});
const authUrl = gyazoAdmin.makeAuthorizeURL();
/**
* authUrl = {url:string,state:string}
*/
【Optional】 Please use the "state" parameter to prevent CSRF.
*The "state" parameter is uuidv4.
- The user accesses the generated URL and approves the app.
- Get the "code" and "state" parameters from the callback URL.
- 【Optional】 Check the state parameter.
- Get "access_token" from "code".
const accessToken = await gyazoAdmin.getAccessToken(code);
Upload
Preparation
- Get the user access token or the application access token.
- Load an image data.
Upload to Gyazo
//base64
const uploadRes = await gyazoAdmin.uploadBase64(accessToken,base64);
//buffer
const uploadRes = await gyazoAdmin.uploadBuffer(accessToken,imageData,"png")
*You can't upload from a browser, because of the CORS policy
Others
File/Blob->Base64 Conversion (Browser Only)
import {readAsDataURL} from 'wrap-gyazo';
const base64 = await readAsDataURL(file);
Thanks for the Reference
Pull Request
If you want to add a feature, please submit a pull request.