Hi again, Im trying to send multiple attachments using external API to OSTicket. However, Im always getting SYSTEM File Import Error: Unable to save file.

Here is part of my code:

if ($attachment) {
$localPath = '/inquiry_attachments/';

    $processedArray = [];

       foreach ($attachment as $filename) {
        $localFilePath = $localPath . $filename;

        if (Storage::exists($localFilePath)) {
            $processedArray[] = $localFilePath;
        }
    }

    $result = $processedArray;
} 

$data = [
'name' => $request->input('requester_name'),
'email' => $request->input('division_email_add'),
'subject' => $request->input('school_name'),
'region' => $inqdata->region_name,
'issue_type'=> $inqdata->inquiry_type,
'service_request_type' => $inqdata->service_report_type,
'message' => "data:text/html,$htmlBody",
'attachments' => $result,
];

Always appreciate for the help.

    Hi Kevin,

    The attachments being saved file to OSTicket are being attached as file format only. Im sure Im still missing on something.

    $attachments = $request->file('inquiry_attachment');

    $attachmentData = [];

    foreach ($attachments as $attachment) {
    $path = $attachment->store('inquiry_attachments', 'public');
    $path1 = public_path('/' . $path);
    $type = pathinfo($path1, PATHINFO_EXTENSION);

                $mime='data:text/plain;';
                $imgext=array("jpg","jpeg","gif","png","bmp");
                $excelext=array("xlsx","xls");
                $pdfext=array("pdf");
                $docext=array("doc","docx");
                
                if(in_array($type, $imgext)){
                $mime="data:image/".$type.";";   
                }
                if(in_array($type, $pdfext)){
                $mime="data:application/".$type.";";      
                }
                if(in_array($type, $excelext)){
                    if($type=="xlsx")
                    $mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;";
                    else
                    $mime="application/msword;";    
                }
                if(in_array($type, $docext)){
                    if($type=="docx")
                        $mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document;";
                    else
                        $mime="application/msword;";
                }
                    
    
                $attachmentData[] = [
                'name' => $attachment->getClientOriginalName(),
                'data' => $path1,
                'type'  => $mime,
                'encoding' => 'base64',
                ];
            }  [upl-image-preview url=https://forum.osticket.com/assets/files/2023-10-10/1696910150-840253-sample-capture.png]

    Thank you for the help.

      Write a Reply...