Skip to content

Instantly share code, notes, and snippets.

@alfiebesin
Created December 23, 2014 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfiebesin/6c26e645cf9fd954cfa3 to your computer and use it in GitHub Desktop.
Save alfiebesin/6c26e645cf9fd954cfa3 to your computer and use it in GitHub Desktop.
Netsuite Upload image to File Cabinet
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$uploadFile = new File();
$uploadFile->name = 'SD Sample Image 9';
$uploadFile->attachFrom = '_computer';
$path = 'alfie.jpg';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$base64Image = $base64;
$uploadFile->content = $base64Image;
$folderRef = new RecordRef();
$folderRef->internalId = 19;
$uploadFile->folder = $folderRef;
$uploadFile->fileType = '_JPGIMAGE';
$uploadFile->mediaTypeName = 'JPEG Image';
$request = new AddRequest();
$request->record = $uploadFile;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD ERROR";
echo '<pre>';
print_r($addResponse);
} else {
echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
echo '<pre>';
print_r($addResponse);
}
@kishan041
Copy link

HI , I want to know how to upload pdf file into NetSuite API.
I tried to upload PDF file but the error is coming ' Please enter value(s) for: Folder'
what value will come in the FIle url.
Please help me out in this.
Thank you

@ivanburrola
Copy link

Try
$uploadFile->folder = new RecordRef();
$uploadFile->folder->internalId = 19;

instead of
$folderRef = new RecordRef();
$folderRef->internalId = 19;

$uploadFile->folder = $folderRef;

@faisalahsan
Copy link

Hi,
Can we save image directly form web URL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment