如何解决PHP-在heroku上处理映像,而无需将其保存在服务器上
我正在尝试在heroku上处理图像文件。我创建了一个端点,该端点将使用Slim 4接受POST请求,并且在前端使用vue。
PHP heroku代码
<?php
//use DI\ContainerBuilder;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\UploadedFileInterface;
use Slim\Factory\AppFactory;
require_once __DIR__.'/vendor/autoload.php';
header("Access-Control-Allow-Origin: http://localhost:8080");
header('Access-Control-Allow-Credentials: true');
//$containerBuilder = new ContainerBuilder();
//$container = $containerBuilder->build();
//$container->set('upload_directory',__DIR__ . '/tmp');
//AppFactory::setContainer($container);
$app = AppFactory::create();
$app->get('/',function(Request $request,Response $response,$args){
$response->getBody()->write('Hello');
return $response;
});
$app->post('/compress',Array $args){
var_dump($args);
// $payload = $args["payload"];
// $dir = __DIR__.'/tmp/';
// //$directory = $this->get('upload_directory');
$uploadedFiles = $request->getUploadedFiles();
// // handle single input with single file upload
$uploadedFile = $uploadedFiles['image'];
var_dump($uploadedFile);
// if($uploadedFile->getError() === UPLOAD_ERR_OK) {
// //$filename = moveUploadedFile($directory,$uploadedFile);
// $im = new Imagick($uploadedFile);
// Morpheus\Data::write($payload,$im);
// $im->writeImage($dir.'output.jpg');
//$response->getBody()->write('no error');
// }
return $response;
});
$app->run();
?>
对代码进行注释,因为我在使用axios从客户端获取数据时遇到了一些麻烦。我无法获得作为我发出的发布请求一部分的有效负载。由于我不想保存图像而是仅对其进行处理,因此,我现在正尝试将上传的文件直接传递到将对其进行操作的库。
VUE客户端应用
handleUpload() {
let formData = new FormData();
formData.append('image',this.$refs.masterImage.files[0]);
// the payload is generated into another method and is an array that I will convert into string
// on the server this will not be recognized
formData.append('payload',JSON.stringify(this.payload));
let config = {
header: {
'Content-Type': 'multipart/form-data',},withCredentials: true //only for debug on localhost
}
axios.post('http://localhost:3000/compress',formData,config)
.then( (response) => {
console.log(response,response.data);
});
} //
我如何在Imagick上使用上传的文件而不将其保存在heroku上(我知道每次dyno重新启动时都会删除这些文件!),然后将其传递回处理以便用户可以下载?我正在尝试使用morpheus一个用于隐写术的php库,我想在将有效载荷返回给用户之前将其放入图像中。我怎么能做到这一点?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。