Autodesk Forge: adding image files Specified image protocol is invalid - image-uploading

I have created a photoscene in Autodesk Forge. Now I am now trying to upload files to it using this PHP code and my uploads are failing. You can check the urls of the images exist online, are jpgs, and should be acceptable to Forge. (I have also tried uploading them as local files and received the same error messages).
What's preventing Forge from accepting my images, and how do I fix it?
foreach( $files_for_forge as $url )
{
$curl_cmd =
"curl -s $FORGE_URL/photo-to-3d/v1/file " .
"-H 'Authorization: Bearer $access_token' " .
"-d 'photosceneid=$photosceneID' " .
"-d 'type=image' " .
"-d 'file[$filecounter]=$url' "
;
$json = shell_exec ( $curl_cmd );
echo "File $filecounter: $url => $json<br />";
$filecounter++;
}
The resulting output shows every file upload attempt is failing with this error: "Error":{"code":"18","msg":"Specified image protocol is invalid"}
File 0: cloud1.tri-di.com/scans/D-A000-5d008f27/original_images/img-13.jpg => {"Usage":"0.67387795448303","Resource":"\/file","Error":{"code":"18","msg":"Specified image protocol is invalid"}}
File 1: cloud1.tri-di.com/scans/D-A000-5d008f27/original_images/img-22.jpg => {"Usage":"0.70915198326111","Resource":"\/file","Error":{"code":"18","msg":"Specified image protocol is invalid"}}
File 2: cloud1.tri-di.com/scans/D-A000-5d008f27/original_images/img-12.jpg => {"Usage":"0.76431202888489","Resource":"\/file","Error":{"code":"18","msg":"Specified image protocol is invalid"}}
...
File 18: cloud1.tri-di.com/scans/D-A000-5d008f27/original_images/img-20.jpg => {"Usage":"0.74234795570374","Resource":"\/file","Error":{"code":"18","msg":"Specified image protocol is invalid"}}
File 19: cloud1.tri-di.com/scans/D-A000-5d008f27/original_images/img-23.jpg => {"Usage":"0.73936891555786","Resource":"\/file","Error":{"code":"18","msg":"Specified image protocol is invalid"}}
I checked the status of the photoscene with this API call:
curl -s https://developer.api.autodesk.com/photo-to-3d/v1/photoscene/KIpe815PrmsCr1Wp73gMFcXQs9wD27P1n1OLiBNfALU/properties
and it returns the following information about my photoscene, showing no files are being attached:
{
"Usage":"0.70800614356995",
"Resource":"\/photoscene\/KIpe815PrmsCr1Wp73gMFcXQs9wD27P1n1OLiBNfALU\/properties",
"next_token":{},
"Photoscenes":{
"Photoscene:{
"photosceneid":"KIpe815PrmsCr1Wp73gMFcXQs9wD27P1n1OLiBNfALU",
"itemName":"KIpe815PrmsCr1Wp73gMFcXQs9wD27P1n1OLiBNfALU",
"clientID":"HAqDtKO7VbuRgH0nL0MFJ0B02ElBEK3l",
"clientStatus":"CREATED",
"type":"all",
"userID":"DtX37KrG1KKBKOHbphoDMzRfn0k=",
"convertStatus":"CREATED",
"projectID":"KIpe815PrmsCr1Wp73gMFcXQs9wD27P1n1OLiBNfALU",
"engineVersion":"3.0.0.3104",
"convertFormat":"rcm,obj,fbx",
"userAgent":"PF_APIv3.2.473-Photofly-WebAPI-FORGE",
"creationDate":"2019-06-26T22:06:23",
"name":"sonautics-D-A000-5d008f27-20190626150712",
"maxResolutionForImage":"100000000",
"UseTitanTextureEngine":"1",
"scenetype":"object",
"status":"PROCESSING",
"Files":{}
}
}
}

Try again and make sure your URL starts with http or https.
Otherwise our server will not treat them as remote resources and proceed to download.

Related

Error code 500: Internal server error (ReactPHP)

I tried to make a server file for my ReactPHP app following this video but when I started up the server, it ran successfully, but when I made a simple http GET the response was "Error code
500: Internal server error", when in theory it should've returned a JSON {"message": "Hello"}.
Here is the code for the server.php file:
use React\Http\Server;
use React\Http\Response;
use Psr\Http\Message\ServerRequestInterface;
use \React\EventLoop\Factory;
require 'vendor/autoload.php';
$loop = Factory::create();
$server = new Server(function (ServerRequestInterface $request) {
return new Response(
200, ['Content-Type' => 'application/json'], json_encode(['message' => 'Hello'])
);
});
$socket = new \React\Socket\Server('127.0.0.1:8000', $loop);
$server->listen($socket);
echo "Listening on ".str_replace('tcp', 'http', $socket->getAddress()). PHP_EOL;
$loop->run();
request.http file:
GET 127.0.0.1:8000
What the request has returned:
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain
Server: ReactPHP/1
Date: Fri, 20 Aug 2021 09:03:19 GMT
Content-Length: 32
Connection: close
Error 500: Internal Server Error
Can someone say to me what the problem is? I think I miswrote something in the server.php file but I am not the one to tell
Code you use from a video is a bit outdated.
If you need a quickfix - just replace one line and it will work:
--- use React\Http\Response;
+++ use React\Http\Message\Response;
Working code for this example (as for react/http-1.5.0) would be
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Loop;
use React\Http\HttpServer;
use React\Http\Message\Response;
use React\Socket\SocketServer;
require_once __DIR__ . '/vendor/autoload.php';
$loop = Loop::get();
$server = new HttpServer(function (ServerRequestInterface $request) {
return new Response(
200, ['Content-Type' => 'application/json'], json_encode(['message' => 'Hello'])
);
});
$socket = new SocketServer('127.0.0.1:8000');
$server->listen($socket);
echo 'Listening on ' . str_replace('tcp', 'http', $socket->getAddress()) . PHP_EOL;
$loop->run();
List of changes:
Response class location (actual fix)
loop factory changed, deprecation upFactory::create() -> Loop::get
http-server changed React\Http\Server -> React\Http\HttpServer
socket-server changed React\Socket\Server -> React\Socket\SocketServer
The answer provided by Ilya Urvachev is the right one, basically react evolved and the Response class is not located in the same location anymore.
Overall after instantiating your server I recommend you to use this line of code so you get error messages in your command line interface:
$server->on('error', function (Exception $exception) {
echo $exception->getMessage() . PHP_EOL;
});
All in all, It's been very difficult for me to move from regular PHP to reactphp, which completely destroy the verbosity of error messages. Ie. You've got exception telling you that the format of the answer is not the expected one, while, what really fucks up your code is that have an error in the syntax of one of your MySQL queries, which sends back a message that is not respecting the expecting answer's format. If someone wants to provide additional way to improve the reactphp verbosity, feel free :)

Curl Post request to upload .zip file to Sharepoint returning "Compressed (zipped) folder invalid when downloading

I have a curl Post request that attempts to upload the latest documents to our Sharepoint. It appears to work fine, the file I send is valid and opens fine before I send it. Once it arrives on sharepoint the filesize is the same but when I download it appears to be corrupted and wont open.
I have tried manually uploading the zip file to Sharepoint, it works fine this way.
I have also scanned the internet for some solution to the problem but I am unable to find anything.
curl -X POST
"http://12.3.456.78:8080/TEST-2.0/sharepoint?relativePath=Shared%20Documents%2FRelease%20Documents%2Fv1&teamSite=Test"
-H "accept: /" -H "Content-Type: multipart/form-data" -F "file=#Test.zip;type=application/x-zip-compressed"
I expect the file on sharepoint to be valid and open correctly after download but I get the following error.
"Windows cannot open the folder.
The Compressed (zipped) Folder 'C:\Test.zip' is invalid.'
The answer was within the code, although the file was sending, it was obviously not sending correctly which was causing the corruption.
The line that I added that made the difference was the following.
post.setEntity( new FileEntity(file) );
My full method can be found below, feel free to comment if anyone needs further information on this in the future.
public HttpResponse uploadFile( String teamSite,
String relativePath,
String accessToken,
File file ) throws IOException
{
String fileName = null;
HttpClient client = HttpClientBuilder.create().build();
fileName = file.getName().replaceAll( " ", "%20" );
relativePath = relativePath.replaceAll( " ", "%20" );
teamSite = teamSite.replaceAll( " ", "%20" );
HttpPost post = new HttpPost( URL );
post.setHeader( "Accept", "application/json;odata=verbose" );
post.setHeader( "Authorization", "Bearer " + accessToken );
post.setEntity( new FileEntity(file) ); //This line here
HttpResponse response = client.execute( post );
HttpEntity entity = response.getEntity();
#SuppressWarnings("unused")
String responseString = EntityUtils.toString( entity, "UTF-8" );
return response;
}

POST request on arduino with ESP8266 using WifiESP library

I am attempting to make RESTful POST request using the WifiESP library (https://github.com/bportaluri/WiFiEsp). I'm able to successfully make the request with curl, but consistently get an error using the Arduino and ESP. I suspect the problem is related to the manual formatting of the POST request the library requires, but I don't see anything wrong. Here my sanitized code:
if (client.connect(server, 80)) {
Serial.println("Connected to server");
// Make a HTTP request
String content = "{'JSON_key': 2.5}"; // some arbitrary JSON
client.println("POST /some/uri HTTP/1.1");
client.println("Host: http://things.ubidots.com");
client.println("Accept: */*");
client.println("Content-Length: " + sizeof(content));
client.println("Content-Type: application/json");
client.println();
client.println(content);
}
The error I get (via serial monitor) is this:
Connected to server
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 3
[WiFiEsp] Disconnecting 3
My successful curl requests looks like this:
curl -X POST -H "Content-Type: application/json" -d 'Some JSON' http://things.ubidots.com/some/uri
After some experimentation, here is the solution to the multiple problems.
The JSON object was not correctly formatted. Single quotes were not accepted, so I needed to escape the double quotes.
The host does not need "http://" in a POST request; POST is a HTTP method.
The sizeof() method returns the size, in bytes, of the variable in memory rather than the length of the string. It needs to be replaced by .length().
Appending an integer to a string requires a cast.
This is the corrected code:
if (client.connect(server, 80)) {
Serial.println("Connected to server");
// Make the HTTP request
int value = 2.5; // an arbitrary value for testing
String content = "{\"JSON_key\": " + String(value) + "}";
client.println("POST /some/uri HTTP/1.1");
client.println("Host: things.ubidots.com");
client.println("Accept: */*");
client.println("Content-Length: " + String(content.length()));
client.println("Content-Type: application/json");
client.println();
client.println(content);
}
The code explained by Troy D is right and it's working .I think the error in posting the data to the server is due to this line
client.println("Content-Length: " + sizeof(content));
and the correct way is
client.println("Content-Length: " + String(content.length()));
Now coming to this error
Connected to server
[WiFiEsp] Data packet send error (2)
[WiFiEsp] Failed to write to socket 3
[WiFiEsp] Disconnecting 3
This is the error of library you can ignore it.
The problem with "Data packet send error (2)", "Failed to write to socket 3" and "Disconnecting 3" is not a problem within the WifiEsp library as far as I can see, believe it's more likely to be within the AT firmware. By default the http headers contain a "Connection: close" parameter which in normal cases should be correct. However with this bug the server will get disconnected before the reply is received on the client side and any response from the server will be identified as garbage data. Using the value "Connection: keep-alive" as a workaround will make it possible to receive the acceptance from the server in a proper way.
I'm running my Arduino + ESP8266-07 against a MVC based Web Api that I created on one of my servers and in the controllers Post-method I use a single string as return value, the value I return if everything is ok is simply one of the strings that WifiEsp keeps track of (It will still include the http status code in the response header that it returns)
public async Task<string> Post([FromBody]JObject payload)
{
//Code to handle the data received, in my case I log unit ip, macaddress, datetime and sensordata into a db with entity framework
return "SEND OK";
}
So in your Arduino code try following instead:
String PostHeader = "POST http://" + server + ":" + String(port) + "/api/values HTTP/1.1\r\n";
PostHeader += "Connection: keep-alive\r\n";
PostHeader += "Content-Type: application/json; charset=utf-8\r\n";
PostHeader += "Host: " + server + ":" + String(port) + "\r\n";
PostHeader += "Content-Length: " + String(jsonString.length()) + "\r\n\r\n";
PostHeader += jsonString;
client.connect(server.c_str(), port);
client.println(PostHeader);
client.stop();
In the file debug.h located in the library source code you could alter a define and get more output to your serial console. Open the file and change
#define _ESPLOGLEVEL_ 3
to
#define _ESPLOGLEVEL_ 4
Save the file and recompile/deploy your source code to your Arduino and you will get extensive information about all AT commands the library sends and what the library receives in return.

Upload a video captions file to Facebook?

According to Facebook's documentation and this bug report the contents of the .srt file should be in the captions_file parameter. I have tried doing this, but continue to get the error:
facebookSDK.GraphAPIError: (#100) Invalid file. Expected file of one of the following types: application/octet-stream
This is the same error Facebook user Ravi mentions in the bug report. What am I doing wrong? Do the file contents need to be converted to binary? Does a Content-Type:application/octet-stream header need to be added? What specifically needs to be sent via HTTP request?
I had the same issue - used the Facebook's SDK for PHP this is actually a bug in the Facebook SDK , solved it by extending the FacebookFile class used for upload
I use the following when trying to upload a captions file :
class FacebookCaptionsFile extends \Facebook\FileUpload\FacebookFile
{
/**
* override the original method since srt is not amongst the known file types in the facebook Mimetypes
*/
public function getMimetype()
{
return 'application/octet-stream';
}
}
and the call :
public static function uploadCaptions($appId, $appSecret, $accessToken, $videoId, $filePath, $locale)
{
if (!file_exists($filePath))
throw new Exception("Captions file given does not exist: ".$filePath);
//create file name in format: filename.locale.srt
$newFilePath = basename($filePath, '.'.pathinfo($filePath, PATHINFO_EXTENSION)).'.'.$locale.'.srt';
copy($filePath, $newFilePath);
$data = array (
'captions_file' => new FacebookCaptionsFile($newFilePath),
);
self::helperChangeVideo($appId, $appSecret, $accessToken, $data, $videoId, false, "/captions" );
}
I logged a bug to Facebook about this and the solution was to use locally stored file instead of URL. For example:
curl -i -X POST -F "captions_file=#\"subs.bg_BG.srt\"" https://graph.facebook.com/v2.7/***/captions?access_token...

imagick error: 'unable to open image' image upload

I get the following error when trying to process uploaded images with imagick.
Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `9eK59iu.jpg': No such file or directory # error/blob.c/OpenBlob/2644' in D:\PATH\upload.php on line 77
The code looks like this:
<?php
$new_folder_name = "D:/PATH/content";
mkdir("$new_folder_name",0700);
$tmp_img = $_FILES["upload_file"]["tmp_name"];
$img = new Imagick($tmp_img);
$img->thumbnailImage(100 , 100 , TRUE);
$img->writeImage($new_folder_name);
?>
Without imagick the image upload works just fine.
Only imagick won't open the image given to $_FILES
I also tried to open the image with imagick, after move_uploaded_file, like this:
<?php
$extension = pathinfo($upload_file_name, PATHINFO_EXTENSION);
$new_upload_file_name = rand(00000, 99999).".".$extension;
$new_folder_name = "D:/PATH/content".time();
mkdir("$new_folder_name",0700);
$path_to_file = $new_folder_name."/".$new_upload_file_name;
move_uploaded_file($_FILES["upload_file"]["tmp_name"],$path_to_file);
$img = new Imagick($path_to_file);
$img->thumbnailImage(100 , 100 , TRUE);
$img->writeImage($new_folder_name);
?>
neither works.. :-(
Any suggestion?
Read the file upload docs. The server-side temporary filename assigned by PHP to store the uploaded file in ['tmp_name'] in the $_FILES array. You're trying to use the client-side user-provided ['name'], which DOES NOT exist anywhere on your server.
$tmp_img = $_FILES["upload_file"]["tmp_name"];
^^^^
You are also simply assuming that the upload has succeed. That is NOT a good thing. Never EVER assume success with dealing with remote resources (web apis, file uploads, database operations, etc...). ALWAYS check for errors:
if ($_FILES['upload_file']['error'] !== UPLOAD_ERR_OK) {
die("Upload failed with error code " . $_FILES['upload_file']['error']);
}