Fixed: #84 && add multi copy

This commit is contained in:
Molunerfinn
2018-07-23 22:24:18 +08:00
parent ce9c2aed71
commit 930e4e663b
4 changed files with 42 additions and 13 deletions

View File

@@ -50,7 +50,7 @@ const imgFromPath = async (imgPath) => {
name = await waitForRename(window, window.webContents.id)
}
let buffer = await fs.readFile(item)
let base64Image = Buffer.from(buffer, 'binary').toString('base64')
let base64Image = Buffer.from(buffer).toString('base64')
let imgSize = sizeOf(item)
results.push({
base64Image,
@@ -105,7 +105,7 @@ const imgFromUploader = async (files) => {
name = await waitForRename(window, window.webContents.id)
}
let buffer = await fs.readFile(item.path)
let base64Image = Buffer.from(buffer, 'binary').toString('base64')
let base64Image = Buffer.from(buffer).toString('base64')
let imgSize = sizeOf(item.path)
results.push({
base64Image,

View File

@@ -3,6 +3,7 @@ import * as img2Base64 from './img2base64'
import db from '../../datastore/index'
import { Notification, clipboard } from 'electron'
import crypto from 'crypto'
import mime from 'mime-types'
// generate COS signature string
const generateSignature = (fileName) => {
@@ -67,7 +68,7 @@ const postOptions = (fileName, signature, imgBase64) => {
headers: {
Host: `${options.bucket}.cos.${options.area}.myqcloud.com`,
Authorization: `q-sign-algorithm=sha1&q-ak=${options.secretId}&q-sign-time=${signature.signTime}&q-key-time=${signature.signTime}&q-header-list=host&q-url-param-list=&q-signature=${signature.signature}`,
contentType: 'multipart/form-data'
contentType: mime.lookup(fileName)
},
body: Buffer.from(imgBase64, 'base64'),
resolveWithFullResponse: true