Upload image from Library Photos iOS to cakephp - php

I'm trying to upload an UIImage that I took from the library photos on iOS to cakephp. The problem I'm really a beginner on cake so I have no idea how it works. I added the plugin: cakemanager/cakephp-utils to cake then added an upload behavior then in my table I initialized my attribute just like this
$this->addBehavior('Utils.Uploadable', [
'control_mfront' => [
'fields' => [
'filePath' => 'control_mfront',
],
'field' => 'id',
'path' => '{ROOT}{DS}{WEBROOT}{DS}img{DS}{model}{DS}{field}{DS}',
'fileName' => 'control_mfront'.date('YmdHis').'.{extension}','removeFileOnUpdate' => false
]
]);
and on my Controller on the post I wrote this :
$this->request->data['model_mfront']['name'] = 'model_mfront';
until now on the website it works fine but for iOS i didn't understand how should I post the image . is it on NSData format !?
and what next ?!
thanks

You can convert your imagedata(NSData) in base64 string and then send it to server as post request.

Related

Possibly recoverable warning exit code from extractor: -536870935 when translating Revit source file

I have been following along with the Translate a Revit File, Generating Room and Space Information tutorial. Right now I'm stuck on task 3 trying to translate a Revit source file to SVF2.
Using the provided Revit file and the following request POST https://developer.api.autodesk.com/modelderivative/v2/regions/eu/designdata/job:
// Headers
[
'Authorization' => ...,
'Content-Type' => 'application/json',
'x-ads-force' => true,
]
// Body
[
"input" => [
"urn" => "<some urn>",
"compressedUrn" => false
],
"output" => [
"destination" => [
"region" => "EMEA"
],
"formats" => [
[
"type" => "svf2",
"views" => [
"2d",
"3d"
],
"advanced" => [
"generateMasterViews" => true
]
]
]
]
]
I always get the following messages:
Revit-UnsupportedFileType
The file is not a Revit file or is not a supported version. TranslationWorker-RecoverableInternalFailure
Possibly recoverable warning exit code from extractor: -536870935
I hope someone can tell what is wrong with the POST request. I found a similar question but the answer doesn't seem apply to this issue.
I actually tried this same tutorial myself and it works perfectly on my end. As long as you follow every step, you are supposed to get the desired result.
If you're running into an error in the third task, it shows there might be something you didn't do correctly in Task 2.
There are a few steps you should check in Task 2 that Task 3 is dependent upon. Please check the following:
Make sure your file is fully uploaded. Look at "Upload the file" section in Task 2 of the tutorial.
You must inform OSS (Object Storage Service) that the upload operation is complete. Look at "Finalize Upload" section in Task 2.
These actions should ensure that your file is fully uploaded and ready to be translated to SVF2
NOTE: When doing all these processes, make sure your Access Token is valid as it only remains valid for one hour. If the token expires, you must obtain a fresh token by sending an authenticate request to Forge once again.
When asking the question I was using the following code to upload the file to Autodesk using Laravel's http client:
$response = Http::attach( 'file', $file->getContent(), $file->getClientOriginalName() )
->put( $signed_url );
This did upload the files and everything worked for zipped models. But as explained in the question plain source files like .ipt or .rvt did not translate.
I guess Laravel is adding something to that request that somehow corrupts files for Autodesk. Using the following request:
$response = Http::withHeaders( [
'Content-Disposition' => 'attachment; filename='.$file->getClientOriginalName(),
'Content-Length' => $file->getSize(),
] )
->send(
'PUT',
$signed_url,
[
'body' => $file->getContent(),
]
);
it does work. I guess using send, sends a "raw"/ binary request.
In Symfony it would look something like:
$response = HttpClient::create()->request(
'PUT',
$signed_url,
[
'body' => $file->getContent(),
'headers' => [
'Content-Disposition' => 'attachment; filename='.$file->getClientOriginalName(),
'Content-Length' => $file->getSize()
]
]
);
I'm not familiar with Lavarel so I might not offer much help on that part.
However, you could try and use another framework like Nodejs or even .NET to try and see if you can achieve your desired results.
You can follow this tutorial that will help you get started in creating your application on top of the Autodesk platform using either Nodejs or .NET framework: https://forge-tutorials.autodesk.io/
You will get to use the Model Derivative API and you can then try and convert the model as intended.

How to Commit Mp3 Files to Folders in Gitlab through API

I am trying to commit a file to Gitlab through the API.
The code had been working for over 6 months but now has stopped working, nothing in the code had changed. The file is commited to Gitlab, however it is corrupted.
I have went through the Guzzle documentation and everything looks correct, and I have done the same for the Gitlab documentation about commits.
I am now using the Laravel Illuminate/Http class to send the commits but the same thing is still happening. I am able to commit to Gitlab, but the file is not formatted correctly.
$response = Http::withHeaders([
'PRIVATE-TOKEN' => $gitlab_token,
])
->post('https://gitlab.com/api/v4/projects/.../repository/commits/', [
'branch' => 'test-branch',
'commit_message' => 'Updated audio file test.mp3',
'actions' => array(array(
'action' => 'update',
'file_path' => 'filePath/../.mp3',
'content' => base64_encode($var)
)),
]);
If I do not encode the contents of the file to base 64 I get the error:
Malformed UTF-8 characters, possibly incorrectly encoded in file
Has anything changed on the API side that has effected how files are processed for committing? Has anyone else found a solution?
I think you have two problems; first there's no content type specified. The post request will be sent just as multipart/form-data with a file attachment, or application/x-www-url-encoded without. This API is expecting JSON data.
Second, there is a parameter in the commit endpoint to specify file encoding. It defaults to "text" but you are sending a base64-encoded file.
I'm not familiar enough with the Gitlab API to say for sure, but your file_path property looks strange as well; shouldn't it just be ".mp3" to be put into that directory?
Try this:
$response = Http::withHeaders([
'PRIVATE-TOKEN' => $gitlab_token,
'Content-Type' => 'application/json',
])
->post('https://gitlab.com/api/v4/projects/.../repository/commits/', [
'branch' => 'test-branch',
'commit_message' => 'Updated audio file test.mp3',
'actions' => [
[
'action' => 'update',
'file_path' => '.mp3',
'content' => base64_encode($var),
'encoding' => 'base64',
]
],
]);

Is it possible to attach an uploaded file to http request?

I have a form that submits a file to an endpoint. In theory that endpoint takes the file and attaches it to another post request that goes to the API.
I was trying to figure out how to do it with Laravel and read a few things that suggest it's not possible? That the only solution would be save it in a public place and submit the link to the API. Anyone able to shed some light on this? Below is the code that I thought would work but does not send the file.
$this->client->post('/api/endpoint', ['form_params' => ['file' => $request->file('file')->getRealPath()]])
Client being the Guzzle client.
Yes it is. Guzzle Docs
$client->request('POST', '/post', [
'multipart' => [
[
'name' => 'foo',
'contents' => 'data',
'headers' => ['X-Baz' => 'bar']
],
[
'name' => 'baz',
'contents' => fopen('/path/to/file', 'r')
],
[
'name' => 'qux',
'contents' => fopen('/path/to/file', 'r'),
'filename' => 'custom_filename.txt'
],
]
]);
It seems fairly uncommon for APIs to handle file uploads as this is generally something a person does. If i were to do something like this I would first read the contents of the file and base64 encode it. Then send the normal Http POST request with the base64 encoded file content as a string. On the API, you could then decode it and do whatever you need to o with the file.
Dealing with base64 in PHP is fairly simple http://php.net/manual/en/function.base64-encode.php

Woocommerce rest api - Create product via ajax in wordpress

Well, the problem is here. I created a local project to create a product in Woocommerce mounted in wordpress on a remote server. My local project code is this one
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
function creaProd(){
$precio = $_POST['Total'];
$imagen = $_POST['Imagen'];
$descrip = $_POST['Descripcion'];
$tipo = $_POST['Tipo'];
$woocommerce = new Client(
'http://example.com',
'ck_sdfsdfsdfsfdxxx',
'cs_sdfsdfsfsdfaxxx',
[
'wp_api' => true,
'version' => 'wc/v1',
]
);
$data = [
'name' => $tipo,
'type' => 'simple',
'regular_price' => $precio,
'description' => $descrip,
'short_description' => $descrip,
'categories' => [
[
'id' => 9
],
[
'id' => 14
]
],
'images' => [
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
'position' => 0
],
[
'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
'position' => 1
]
]
];
print_r($woocommerce->post('products', $data));
}
creaProd();
And evertything works fine, the problem is, that I have tried a bunch of things, but I just don't get to create the product working in the wordpress project.
I put it in the wp-includes folder and the wp-content, but didn't work.
I tried to call an ajax to example.com/wp-includes/myFile.php but I can't reach it, I can reach files like example.com/wp-includes/option.php and all the files already there, but if I upload that one, I just can't, and I don't know where to put the vendor folder either.
Which is the right way to integrate this project to my real site in Wordpress?
Hope someone knows how to do this. Thanks.
I think the best way to integrate third party libraries into Wordpress is creating your own plugins (This for me is the best option, cause you can use other API Wordpress even security stuff like if a user is login or have the right permissions). they are simple to create and they can be enabled through the Wordpress dashboard admin.
Here is some post about it:
How to create plugin - Wordpress Documentation
in this article you can find how to write a plugin in Wordpress from the official documentation
[Note to reviewer I am the same person as user 8256950. When I tried to create a login for 8256950 it create a new login 8262086 instead. Don't know why but I do destroy all cookies daily.]
Your project is a REST client which is usually run from a different server. It is not part of the WordPress server and I would put its files in its own directory. It is not a plugin. It is also not AJAX. (No JavaScript is used in the REST client to REST server communication but of course the client can be invoked by Javascript.)
Concerning your specific problem reaching files it would be helpful if you provided the Network log from your browser. On Chrome 'More tools' -> 'Developer tools' -> 'Network'. Look for the request for you file and see if there is an error message.

Example of sending POST and FILES data from iPhone to a remote PHP website

I'm programming an API of sorts on a PHP website I built with the goal that another programmer can send data (POST and FILES date) to my PHP website from their iPhone app so that I can process the data and return some of my own.
We've been struggling to find a way that he can send POST data (though we found a pretty hacky workaround) and FILES data from the iPhone app. The goal on my end would be to receive a POST array and a FILES array similar to (in PHP of course):
$_POST = array(
'key' => 'key-value-here',
'token' => 'token-value-here',
'id' => 'id-value-here'
'values' => array(
'name' => 'Name value here',
'description' => 'Description value here'
)
);
$_FILES = array(
'photo' => array(
'name' => 'photo-name.jpg',
'type' => 'image/jpeg',
'tmp_name' => '/tmp/path',
'error' => '0',
'size' => '12345'
)
);
Any help you could offer us on how we could send such data would be greatly appreciated. Also, the iPhone app programmer is trying to avoid using the ASIHTTPRequest library for now (for a number of reasons).
Just create a multi-part post. For how it should look like, see a multi-part message. I have never worked with the iPhone, so I couldn't tell you which library could do this, but if all else fails, it's just an open socket connection & some string manipulation...

Categories