php - 将文件上传到我的 API 时更改了完整文件权限
问题描述
我正在开发一个发送要在服务器上处理的图像的应用程序。服务器在应用程序中接收捕获的图像并使用opencv处理图像。服务器和应用程序都已经在工作,并且两者之间存在通信。服务器内的项目文件夹已经拥有所有权限,如下图所示。问题是,当发送应用程序图像时,包含服务器上接收到的所有图像的默认名称“final.png”,服务器端的权限被更改,因此,服务器无法执行处理,因此更改图像,因为您不再拥有必要的权限。谁能告诉我为什么图像在发送到服务器时会更改权限,或者如何解决在处理图像之前再次授予所有权限?我正在使用 laravel 框架进行服务器开发,并且我的应用程序在本机 android 上。
要处理图像的算法的目录,其中“exec”是处理的算法和相应的图像。
发送图像的响应 API:
图像发送到服务器后:
我的代码服务器:
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Process\Process;
class ClassificationController extends Controller
{
public function process(Request $request)
{
/** @var $image UploadedFile*/
$image = $request->files->get('image');
if (empty($image)) {
throw new \Exception("Arquivo não fornecido.");
}
$validExtensions = ['image/jpeg', 'image/png', 'image/jpg'];
if (!in_array($image->getMimeType(), $validExtensions)) {
dd($image->getMimeType());
throw new \Exception("Arquivo não suportado");
}
if (!$image->move(resource_path('feridas'), $image->getClientOriginalName())) {
throw new \Exception("Error moving file.");
}
$newPath = resource_path('feridas/' . $image->getClientOriginalName());
return $this->processImage($newPath);
}
private function processImage($newPath)
{
var_dump(__DIR__, realpath('.'), realpath('feridas/exec'));
$process = new Process([var_dump(getcwd())]);
$process->run();
$process->wait();
if (!$process->isSuccessful()) {
return [
'success' => true, //ou false
'message' => 'Could not execute script: %s', $process->getErrorOutput()
];
throw new ProcessFailedException($process);
}
$output = $process->getOutput();
$result = json_decode($output, true);
if (null === $result) {
return [
'success' => true, //ou false
'message' => 'Could not decode return value from script from template "%s" (should be a JSON encoded string): %s', $output
];
}
else{
return [
'success' => true, //ou false
'message' => "WORK"
];
}
}
}
解决方案
推荐阅读
- user-interface - 如何在 Flutter 中使用 Timer 显示一个小部件 4 秒
- php - 如何将google ads api与php项目连接起来
- gradle - Gradle 无法从“14.0.1”确定 Java 版本
- sql - 使用 ROW_NUMBER() OVER PARTITION BY 和动态列的 SQL 查询
- arrays - 为什么我的 *ngFor 显示两个空项目
- python - 函数给出错误 ValueError: list.remove(x): x not in list
- xml - 参考 pandas 数据框替换 XML 中的元素
- angular - 在用另一个版本构建的应用程序中使用用一个版本的 Angular 构建的 Angular 库是否安全?
- php - MySQL where NOT IN 除了其中一个
- android - macOS Catalina 10.15.4 - 谷歌地图不工作