Livecode - HTTP POST request - http

I'm trying to send a HTTP POST request in Livecode to a webservice.
This is the code in Livecode:
put 8 into tId
put the text of field "image_text" into tBlop
put tBlop into field "image_text"
put "id=" & tId & "&blop=" & base64Encode(tBlop) & "&pic=" &tBlop into tArgList
post tArgList to URL "http://www.example.com/api_donation/blop2"
put it into tFormResults
The webservice is written in PHP using the Slim framework
$id = $app->request->post('id');
$blop = $app->request->post('blop');
$pic = $app->request->post('pic');
// decode image
$blop = base64_decode($blop);
$db = getDB();
$sql = "INSERT INTO picture (id, blop, pic) VALUES ($id, $blop, $pic)";
$stmt = $db->prepare($sql);
//execute sql statement
$res = $stmt->execute($data);
However when the image is inserted in the db and I try to get it in Livecode, the image stored in the db is not a valid image.
Is the reason for this error the encoding? Do I need to change some settings in the db (e.g. utf-8)?
Thank you for your help!

The properties imageData (binary) or text (ASCII) of an image are livecode properties regarding what is shown on the screen. They aren't bmp, jpg, png or any other format.
If you need to create a valid format, you need the export command.
See http://livecode.wikia.com/wiki/Export

Related

Edit an existing Pastebin document via API

I am trying to write a function in LUA to edit my pastebin code.
I can use this code to make a HTTP post:
http.post(string url, string postData [, table headers])
I can also use this code for a HTTP get:
http.get(string url [, table headers])
on the Pastebin website https://pastebin.com/api are information about using the API.
I am not sure, if this website can help me to solve my problem.
Does someone know how to fill the headers table?
this is the program i tried:
headers = {}
headers["api_dev_key"]= 'myDevKey...'; // your api_developer_key
headers["api_paste_code"] = 'my edited text'; // your paste text
headers["api_paste_private"] = '0'; // 0=public 1=unlisted 2=private
headers["api_paste_name"] = 'justmyfilename.php'; // name or title of your paste
headers["api_paste_expire_date"] = '10M';
headers["api_paste_format"] = 'php';
headers["api_user_key"] = ''; // if an invalid or expired api_user_key is used, an error will spawn. If no api_user_key is used, a guest paste will be created
headers["api_paste_name"] = myPastebinName;
headers["api_paste_code"] = myPastebinPassword;
http.get("https://pastebin.com/edit/dQMDfbkM", headers)
unfortunately this is not working and on the pastebin API help site is no exsample for editing a paste. just for creating a new one.
for me it is also not clear if I have to use post or get
There is no API for editing pastes directly.
You can only delete old paste and create new with updated text.

ASP.NET Cant Open link via email

I created an email in ASP.NET and I want to add a link to the body, but this not a normal url, its a file that is created via byte array and now I want that file to be linkable in my email, but no matter what I do the link is clickable but nothing opens, here is my code:
FileContentResult eventPass = new FileContentResult(generatedPass, "application/vnd.apple.pkpass");
eventPass.FileDownloadName = "preview.pkpass";
message += "<a href='//" + eventPass + "' target='_blank'>Click Here</a>";
AlternateView alternateView = AlternateView.CreateAlternateViewFromString(message, null, MediaTypeNames.Text.Html);
alternateView.LinkedResources.Add(inline);
email.AlternateViews.Add(alternateView);
email.IsBodyHtml = true;
email.Headers.Add("Content-Type", "application/vnd.apple.pkpass");
I know the file is generated correctly because if I return eventPass the file downloads.
Do I need to save eventPass to the server?
Possible answer here:
How to set mime type of application/vnd.apple.pkpass in order to share pass by link or email
Please mark my answer as correct if this has helped you.

NetSuite Advanced PDF Dynamically Created in Script - Cannot Set <img> tag

I am dynamically creating an Advanced PDF in script. I've created an XML string that I am then passing to NetSuite's XML to PDF API; nlapiXMLToPDF(xmlString).
I've added saved searches, tables, styling, and the xml string is parsing correctly.
I cannot add a logo in an tag as I'm not sure how to drill into the file cabinet and store the 'src' of the image.
Has anyone had experience dynamically creating Advanced PDFs in NetSuite and pulling in the logo in a script?
Are you trying to include an image from the file cabinet? If you have the internal ID of the file in the variable fileID, then you can use the following code:
var imageURL = nlapiLoadFile(fileID).getURL();
imageURL = nlapiEscapeXML(imageURL);
var xmlString = ... + '<div><img height="XXpx" width="XXpx" src="'+logoURL+'" /></div>' + ...;
var myPDF = nlapiXMLToPDF(xmlString);
If you want to use the Form Logo set on the Company Information page, then you can populate fileID using the following code:
var companyInfo = nlapiLoadConfiguration('companyinformation');
var fileID = companyInfo.getFieldValue('formlogo');
Then use the first code block to include the logo in xmlString.

How to save image from rich text editor

I have a form including rich text editor in it.
While with only content in richtext editor I don't get any problem in saving it in database.
But when I attach an image in it, It always pokes me with this error-
Invalid URI: The Uri string is too long.
Yes the URI is absolutely so long, But why don't this form saves it even if I had given datatype to nvarchar(MAX) to be saved.
See in pictures-
and URI of this image -
While model type has nvarchar(MAX) datatype for this rich text editor.
I am performing simple save function and rendering rich text editor's values by
#Html.Raw() helper.
For this editor's rendering I am doing this on client side-
#Html.Raw(Model.businessDetails)
Model-
public string businessDetails{get;set;}
Why SQL SERVER doesn't save this long uri? What went wrong in my form submission?
first thing first,
you should be doing this as a POST request not as a GET!
after that you have two options
1)
set an attribute so it will allow HTML in the string and it will store the image as base64 in the html and you won't have to worry about storing it anywhere.
[AllowHtml]
public string businessDetails{ get; set; }
2)
grab the src of the image
remove the data:image/png;base64, from it
decode the result with base64 converter , the resulting is binary result
byte[] imageArr ;
//set your imageArr here---
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.CreateOptions = BitmapCreateOptions.None;
bi.CacheOption = BitmapCacheOption.Default;
bi.StreamSource = new MemoryStream(imageArr);
bi.EndInit();
Image img = new Image(); //Image control of wpf
img.Source = bi;
save image to destination. img.Save("path",ImageFormat.Jpeg)
replace the src of that image with an actual URL

What kind of data Type use to save an image in database

I need to insert images i have locally using SQL.
I'm doing it this way :
CREATE TABLE [dbo].[Table_1](
[SelectedImages] [image] NOT NULL,
[Path] [ntext] NOT NULL
)
to add an image, do this:
INSERT INTO [testing].[dbo].[Table_1]
([SelectedImages]
,[Path])
VALUES
('D:\desktop\05022006\free_chart1.gif' ,'D:\desktop\05022006\free_chart1.gif' )
The problem is i need to retrieve the image afterwards...
I use a Telerik control showing an image stored as binary data in a database
And i'm not sure the type "Image" is the correct one since it's not working...
<telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Photo") %>'
AutoAdjustImageControlSize="false" Width="90px" Height="110px" ToolTip='<%#Eval("ContactName", "Photo of {0}") %>'
AlternateText='<%#Eval("ContactName", "Photo of {0}") %>' />
What kind of data type do you guys use to store an image ?
Thanks in advance
You can store images in the database using image type as you have it defined in your question. However, you need to convert the image into a byte array first.
string path = "D:\\desktop\\05022006\\free_chart1.gif"
using (System.IO.FileStream fstream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
// Create a buffer to hold the stream of bytes
byte[] buffer = new byte[fstream.Length];
// Read the bytes from this stream and put it into the image buffer
fstream.Read(buffer, 0, (int)fstream.Length);
fstream.Close();
//now you can insert buffer into the database
}
When you want to retrieve the image from the database, you have to convert it back from a byte[].
if (byteArray != null)
{
if (byteArray.Length > 0)
{
// Create a new MemoryStream and write all the information from the byte array into the stream
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray, true))
{
ms.Write(byteArray, 0, byteArray.Length);
// Use the MemoryStream to create the new BitMap object
Bitmap photo = new Bitmap(ms);
ms.Close();
//now you can use photo
}
}
}
What kind of data type do you guys use to store an image ?
It depends upon situation & its your call.
Sometimes just storing the URL of image inside a VARCHAR field would
suffice 'C:/Data/UserName/uploads/myGuid+filename.jpg' & actual file is present on disk (transaction management is difficult with this approach but works well for small requirements)
When transaction management is top priority you can store them inside database in VARBINARY(max) field Storing images in SQL
Server
SQL Server filestream is also an option with latest SQLServer on which the file is stored on filesystem managed by database SQL Server filestream Overview

Resources