首页 > 解决方案 > 将文件上传到我的 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"
        ];
    }
}
}

标签: phpandroidlaravelserver

解决方案


推荐阅读