put
只接受文件目录,似乎在函数中无法使用方法put
。使用Uint8Array(data)
,我认为我可以使用新的upload
上传。但它不适用于exports.modificarImagen = functions.storage.object().onChange(event => {
const THUMB_PREFIX = 'thumb_';
const object = event.data;
const fileBucket = object.bucket;
const filePath = object.name;
const contentType = object.contentType;
const resourceState = object.resourceState;
const metageneration = object.metageneration;
const SIZES = [64];
const bucket = gcs.bucket(fileBucket);
const fileName = filePath.split('/').pop();
const tempIconoPath = path.join(os.tmpdir(), 'icono-amarillo.png');
const tempPerfilPath = path.join(os.tmpdir(), 'perfil64.jpg');
return bucket.file('images/icono-amarillo.png').download({
destination: tempIconoPath
}).then(() => {
bucket.file('images/perfil64.jpg').download({
destination: tempPerfilPath
}).then(() => {
_.each(SIZES, (size) => {
let newFileName = 'nueva_imagen.png';
let newFileTemp = path.join(os.tmpdir(), newFileName);
let newFilePath = `images/${newFileName};`
sharp(tempIconoPath)
.flatten()
.background('#ff6600')
.overlayWith(tempPerfilPath, { gravity: sharp.gravity.southeast } )
.sharpen()
.withMetadata()
.raw()
.toBuffer().then(function(outputBuffer) {
//here is the problem. outputBuffer is a raw file uint8array and
// storage only allows file path.
bucket.upload(outputBuffer, {
destination: newFilePath
}).then(() => { console.log("do another thing"); });
});
})//each
})
})
})
方法。
function EmailCheck($sql) {
if (isset($_POST['email'])) {
$newemail = $_POST["email"];
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
echo "Invalid e-mail, please try a different.";
exit;
}
$check_email = $sql->query("SELECT email FROM auth WHERE email='$newemail'");
if ($check_email-> num_rows) {
echo "E-mail is already in use.";
exit;
}
}
else {
mysqli_query($sql, "UPDATE auth SET email='$newemail' WHERE username = '$this->username'");
header("Location: userinfo.php");
exit;
}
}
答案 0 :(得分:0)
您可以将Google Cloud Storage和Sharp与流一起使用。以下应该有效:
function transform(fileBucket, tempPerfilPath, filePath, newFilePath) {
const thumbnailUploadStream = fileBucket.file(newFilePath).createWriteStream();
// Create Sharp pipeline for resizing the image and use pipe to read from bucket read stream
const pipeline = sharp();
pipeline
.flatten()
.background('#ff6600')
.overlayWith(tempPerfilPath, { gravity: sharp.gravity.southeast } )
.sharpen()
.withMetadata()
.raw()
.pipe(thumbnailUploadStream);
fileBucket.file(filePath).createReadStream().pipe(pipeline);
const streamAsPromise = new Promise((resolve, reject) =>
thumbnailUploadStream.on('finish', resolve).on('error', reject));
return streamAsPromise.then(() => {
return console.log('Image created and uploaded successfully');
});
}