Yii CUploadedFile from raw base64 data - base64

Is it possible to create an instance of the CUploadedFile class from raw base64 data sent through a POST variable? I know I could also save the file without using this class, but I need to reuse a model class which uses CUploadedFile to get a file that was uploaded through a form.
I cannot use any file uploader component since my Yii application is a web service. It gets all its input data from POST variables.

CUploadedFile — no but you can try overriding prefetchFiles method in your own class that extends CUploadedFile to fetch data from $_POST instead of $_FILES.

Related

From JSON file to related typeORM entities

Let's say I have a backend that needs to be able to receive big JSON files containing data.
This JSON data should be decomposed into several different tables/entities (in order to be easily manipulated by a frontend).
Those different entities should be in relation to each other (one-to-many/many-to-one relations).
In your opinion, what's the best way populate a db from a JSON file, using nest js and typeORM ?
Thanks in advance for your knowledge,
4coma
you mean fast define entities from a json file.
If right, I usually use app https://app.quicktype.io/ to convert json file to interface type (select language Typescript and interface only)
Then use editor replace interface to class
replace with expression ;\n to ;\n\n\t#Column()\n
replace with expression export class to #Entity()\n export class
then import decorator Column, Entity, add option to column as you need

How can i send image/file and nested json data together using postman?

I am able to send image/file and normal key value which is being served as normal json later. I am using the form-data type of body in postman and a node server.
To handle image i am using multer on my node server.
But what makes issue is when i try to send the nested json and image together.
I am not able to do this thing.
Everything is fine but this is how the nested json is logging in the terminal :-
Please! Any help would be great to get the nested data object also in actual json format but not like this string as shown in terminal photo.
JSON can't contain binary data. What you're asking isn't directly possible.
The ideal thing to do is a multipart request, which is what you're getting in your first example. Note that one of those parts could be JSON, and you can just reference the other part by name, or with some other identifier.
The wrong way to do this is to base64 encode the data and put it in your JSON. If you do this, you'll get what you're asking for at the expense of 33% overhead in file size, wasted CPU and memory on each end for encoding/decoding, and significant waste in memory for your JSON parser which now has to chew through all of this extra data.
An alternative is to use a format that supports binary data, like CBOR. CBOR works in browsers, is streamable, supports all of the types of JSON and then some, is extensible, and standardized.
One solution is to split image upload and record upload into two separate services and call in UI one after the other.
It may be late but I faced the same issue, what I did was,
1: send data through form-data body and had 2 parameters.
file (the file which we want to send on backend using file field)
data (a string in json format using the text field in form-data).
example:
data : {
"words":500,
"model":0,
"video":true,
"user_id":"user1"
}
I sent this in the request. Remember that when we send using form-data we have 2 separate choices file/text. Since this is text so the whole string is considered a text. So, essentially the data parameter is a string. When I receive this request on backend in django I do the following to get the actual json in json format.
attributes = json.loads(request.data['data'])
This converts the data parameter which was first a string, into a json just as we wanted.
Hope it helps others.

Send data from routeHandler to a partial in NodeJS

I have a variable which contains some data. This variable is in a routeHandler file called content.js. Now i have to pass this variable to a partial called nav.hbs that uses it for some calculation. Can anyone help me out with this? Very new to NodeJS.
PS:- I am using handlebars to design the partial.

What JSF data can I store in a client browser

I'm interested can I store into client side for example large hashmap or a List? I need something like a temporary cache to store user session data.
In theory, you could use HTML5 client side storage in JavaScript. So far now, no JSF components exists which could do the job transparently. You'd need to write all the necessary JS code yourself or grab jQuery.
All JSF as being a HTML code generator can do for you is to print Java objects in JSON format as a JavaScript variable assignment with help of a JSON library such as Google Gson.
<h:outputScript>var data = #{bean.dataAsJSON};</h:outputScript>
The getDataAsJSON() should just return an already converted JSON string.

Call a custom document converter using Sharepoint Object Model

How to call a custom SharePoint converter that is activated for a specific website.
For example, the below code is used to get the GUID of that converter
foreach (SPDocumentConverter converter in converters)
{
//Console.WriteLine(converter.DisplayName);
if (converter.ConvertFrom.ToLower().Equals("pdf") && converter.ConvertTo.ToLower().Equals("jpg"))
pdfToJpgConverterId = converter.Id;
}
and the SPFile.Convert method is used to call the converter usually. But when I am trying to call the document converter using SpFile.Convert method, its not calling it.
My custom conveter takes 2 command line arguments. How can I pass them to my converter when I called it using SharePointObject model or some other.
Update:
A document converter is custom executable file, which is deployed to a specific website as a feature. I want to transform the given pdf file into images by supplying the file name to the document converter using Sharepoint object model. SPFile.Convert method has an argument like "-config", which is a third parameter where we pass the required information(parameters). Can anyone help in this regard?
You may want to consider invoking the process directly using Process.Start and passing the command line arguments.

Resources