Document here :
https://developers.google.com/storage/docs/reference-methods#getobject
I use this function try to Download a obejct. But only can response metadata info
getFile: (file_id, callback)->
log("getFileMetadata")
unless callback
callback = (resp) ->
log "Read Complete" ,resp
params =
path : "/storage/v1beta2/b/#{#BUCKET}/o/#{file_id}"
method : "GET"
headers:
host: "storage.googleapis.com"
"If-Modified-Since" : "Fri, 19 Feb 2001 22:04:23 GMT"
alert("12 storage.googleapis.com")
gapi.client.request(paramas,callback)
The selfLink field points to the canonical URL containing the metadata for the object. To get the object's contents, you should use the mediaLink field.
Also had problems trying to download a file using the Google_Storage_Service.
Once I list my object in a given bucket I get an array of items, which each have a media link containing a URL to my file which looks something like
https://www.googleapis.com/storage/v1beta2/b/<bucket>/o/<object>?generation=1234567890&alt=media
So naturally I try and download this file using Google_Http_Request (perhaps there is a better way?)
$request = new \Google_Http_Request($item->getMediaLink(), 'GET');
$httpRequest = $this->googleClient->getAuth()->authenticatedRequest($request);
But I got an error message saying....
*The document has moved here*
So downloading from the following works, note the change in the sub domain
https://storage.googleapis.com/<bucket>/<object>?generation=1234567890
Related
I'm using Talend Open Studio for ESB - Version: 8.0.1. I have a job that loops thru data and creates a CSV for each data element, like this:
> ID DATA
> A QQQQ#$%$
> B WWWE^UTU
etc. The job creates FileA.csv, then FileB.csv etc. That all works, but the next step I need will take FileA.csv and POST that data to an API.
The URI for each file is different, so I'm using a context to create the link. The links look like this:
https://:#host/updatenodes?application_code=fileA
There is a different application code for each file. I've tested the link for these files in Postman, and they all work, here's the message:
"result": "success",
"message": "Update batch submitted with 0 items",
"threadId": []
So, the links are correct. In Talend ESB, I'm using a tFileFetch object with Post Method checked. The file image_Tal.png shows the settings
of the tFileFetch. When I use a context URL, I get this error:
> Exception in component tFileFetch_1 (Cognosos)
> java.lang.IllegalArgumentException: host parameter is null
I also tried hard-coding the full URL into the filefetch object, I get this error:
Sep 08, 2022 1:49:39 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: no further information
So, how do I post the data from the CSV to the API? I've tried tRest, but it wouldn't allow me to use a context variable as the URI.
Because each different file has a different ID/Password, I need to use a variable for each iteration in the loop. When I use a
context for the URI, it gives me the error "URI is not absolute". I had the same problem with RestRequest and RestClient.
Are there some settings I need to add to Talend ESB? I'm using the defaults now - I'm not sure what settings to change.
![enter image description here](https://i.stack.imgur.com/A6NA3.png)
I've tried the tRest and tRestRequest objects, but I got and error using a context for the URI. I'm trying to get the CSV data to POST to the API.
Is there a way to achieve downloading via. the google-php-api? I have tried the following:
using the medialink and trying to curl the object (Returns "Login Required")
reading the guzzle response stream (comes back empty even though all the headers have the correct data)
I am able to see everything but the body of the file via. the API.
Edit:
I am of course able to download the file via the medialink, taken it is set to public - however that will not work for this situation.
The solution is as follows...
You must make an authorized HTTP request, to do this you must:
$object = $service->objects->listObjects(BUCKET, OBJECT);
$http = $client->authorize();
$request = new GuzzleHttp\Psr7\Request('GET', $object->getMediaLink());
$response = $http->send($request);
$body = $response->getBody()->read($object->getSize());
The above is a small snippet but the jist of what you need to get the contents of a file.
I'm building an application that inserts documents into MarkLogic server using the MLPHP library. The problem is when I insert a binary document, for example a PDF. The mime type will not be set properly, therefore the file cannot be opened as it should.
This is the code I use to insert a document:
// initialize REST client
$client = new MLPHP\RESTClient('127.0.0.1', 8010, 'v1', '', 'rest-writer-user', 'writer-pw');
// create new document and load content
$doc = new MLPHP\Document($client);
$doc->setContentType("application/pdf");
$doc->setContentFile("demo.pdf");
$doc->write('pdf_demo');
This is a dump of the $doc object after submitting to the server:
And here we have the inserted document in the search results:
But as expected, the browser cannot handle the file due to the wrong mimetype:
Anyone has got a clue what's going wrong here?
Check to see what the Response Header for content type is.
You Might have to set the format URL Parameter to binary. You can read the full documentation at http://docs.marklogic.com/REST/GET/v1/documents
here is what the request would look like
http://localhost:8010/v1/documents?uri=/pdf_demo.pdf&format=binary
I have a class that models exactly the entity I have in the database. I have a stored procedure that takes in parameters for a new row and returns all the settings in the table which in turn populates my repository. I am able to see the results of GET, PUT and DELETE in the List of type Setting that is in memory. I am noticing first that even when I close Visual Studio and reopen and run the project, sometimes, the List is still in the state it was before. It is not repopulating from the database so I'm not sure why that is first of all... Secondly, I can't seem to get POST to work from Fiddler unlike the other HTTP verbs. I DO see the values from Fiddler show up in the code below but I get the error: Invalid URI: The format of the URI could not be determined. I get the same error if I pass an ID or not.
Here is what I put into Fiddler:
POST localhost:54852/api/settings
Request Headers
User-Agent: Fiddler
Content-type: application/x-www-form-urlencoded
Host: localhost:54852
Content-Length: 149
Request Body
ID=0&Category=Dried%20Goods&Sub_Category=Other&UnitSize=99&UnitOfMeasureID=999&Facings=true&Quantity=true&EverydayPrice=999.99&PromotionPrice=111.11
PostSetting function within my SettingsController
public HttpResponseMessage PostSetting(Setting item)
{
item = repository.Add(item);
var response = new HttpResponseMessage<Setting>(item) { StatusCode = HttpStatusCode.Created };
string uri = Url.Route("DefaultApi", new { id = item.ID });
response.Headers.Location = new Uri(uri);
return response;
}
Should I create a new procedure that gets the MAXID from the database and use that as the NEW ID in the line above where a new ID is created?
You need to create a JSON representation of the Setting class or item that you are wanting to test with use Fiddler (now a Telerik product) and use the Composer tab.
Next you will want to perform a POST to the following URL:
http://[your base url]/api/settings
and pass the JSON formatted setting class.
You can see an example of this here: ASP.NET Web API - Scott Hanselman
Here is a short video showing how to achieve it easily
get and post to webapi from fiddler
I am trying to submit a batch request to add objects via Open Graph Beta to a user's Timeline but no matter what I do I get this:
The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: egg.
I am specifying an egg property though. My requests look like this:
https://graph.facebook.com/?batch=[{'method':'POST','relative_url':'/me/my_namespace:find','egg':'http%3A%2F%2Fwww.mydomain.com%2Fmy_namespace%2Fog%2Fegg.php%3Ftypeid%3D-966','start_time':'1317439270','end_time':'1317439270'}]&access_token=<<snipped>>&method=post
I am sending egg as a url-encoded reference string to a URL that contains my open graph data -- the URL does work if I send it not as a batch but since when setting up a user's Timeline I will in some cases have to post up to 1000 actions I am trying to speed things up by batching them.
I was able to successfully delete via a batch request.
Instead of sending the 'egg' as a param of the batch object, you need to format this like a query string and send it in the body param.
Also, relative_url should not begin with a '/'
Try posting this instead...
https://graph.facebook.com/batch?access_token=TOKEN&method=post&batch=
[
{
"method": "post",
"relative_uri": "me/your_namespace:find",
"body": "egg=http%3A%2F%2Fwww.mydomain.com%2Fmy_namespace%2Fog%2Fegg.php%3Ftypeid%3D-966&start_time= 1317439270&end_time= 1317439270
}
]
I've tested this and it works.
When Posting data to the batch API, the data must be formatted like a querysting and sent in the 'body' param as a string.