Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

674
Visualizações
how to upload image using http client laravel to API

I want to update/upload an image using http client laravel. I did update the data but the image are not updated. the API are blob type. I try to use form-data file in postman and it did work. but I don't know why it's not working in my laravel app.

this is my code

$image = $request->file('profile_image');
        if ($image != null) {
            $contents = $image->openFile()->fread($image->getSize());
        }
        $response = Http::withToken($request->session()->get('user'))->acceptJson()->attach('image', file_get_contents($image))->post("https://voice.infidea.id/api/gateway/update-user", [
            'id' => $user['id'],
            'name' => $request->name,
            'email' => $request->email,
            'contact' => $request->contact
        ]);

I try to use the $content also but still did not work. only the string data that updated.

this is how I upload it in postman enter image description here

please is there someone know why it is like this, please help I really appreciate it.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You need to specify complete file path for file_get_contents(), change to this

file_get_contents($request->file('profile_image')->getRealPath()));
// or
file_get_contents($request->profile_image->path());

You just place the temp path or complete path of image

$response = Http::withToken($request->session()->get('user'))->acceptJson()->attach('image', file_get_contents($request->file('profile_image')->getRealPath()))->post("https://voice.infidea.id/api/gateway/update-user", [
            'id' => $user['id'],
            'name' => $request->name,
            'email' => $request->email,
            'contact' => $request->contact
        ]);
over 4 years ago · Santiago Trujillo Relatório

0

I think value of $image = $request->file('profile_image'); is not set bcoz in postman you use image.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda