Netsuite PHP 中的文件上传

问题描述 投票:0回答:1

这里的目标是使用 PHP Netsuite 客户端上传 Netsuite 文件柜中的文件

到目前为止我所拥有的:

$file = new File();

$file->folder = new RecordRef();
$file->folder->internalId = XXX;

$file->name = 'filename.png';
$file->fileType = MediaType::_PNGIMAGE;
$file->attachFrom = FileAttachFrom::_computer;

$content = base64_encode(file_get_contents($request->file('file')));
// Outputs a base64 string that can be converted back to an image using any base64=>image tool
$file->content = $content;

$request = new AddRequest();
$request->record = $file;

$addResponse = NetSuite::add($request); // SUCCESS

请求几乎在文件创建时工作,在正确的文件夹中,但是内容不可读

当您从 Netsuite 文件柜下载文件并尝试打开它时,您收到一条错误消息,指出文件已损坏。 当在文本编辑器中打开它时,内容是上传的确切的base64字符串,并且可以在任何base64=>图像工具中转换回图像

有什么建议吗?

php base64 netsuite
1个回答
2
投票

事实证明,该库实际上正在处理 Base64 编码本身

- $content = base64_encode(file_get_contents($request->file('file')));
+ $content = file_get_contents($request->file('file'));

谢谢@劳伦斯!

© www.soinside.com 2019 - 2024. All rights reserved.