Gagri Global IT services is having a team of executives who have good experience in developing applications on various platforms like SharePoint 2013/2010, Silverlight, net Framework 4.5 and Mobile tools.

Image parameter in API

Posted on December 15, 2023 by Amruthavalli,Deeksha

Image parameter in API :

  1. HTTP Request Method
  2. Request Headers
  3. Request Body
  4. File Upload
  5. Parameter Naming
  6. Authentication
  7. Endpoint URL
  8. Response Handling

1.HTTP Request Method:

    • Typically, when working with APIs, you use the HTTP methods like GET, POST, PUT, or DELETE.
    • For sending images, the common choice is often POST, as it allows you to send data in the request body.

2. Request Headers:


    • You might need to set specific headers in your API request. Common headers for dealing with images include Content-Type.
    • To specify the type of content being sent (e.g., image/jpeg), and Authorization if authentication is required.

3.Request Body:


    • If you're using a POST request, the image data would be included in the request body.
    • You may need to encode the image in a specific format, such as base64, or use a more efficient binary format like multipart/form-data.

4. Parameter Naming :


    • Check the API documentation for the correct parameter name for sending images.
    • It's often something like "image," "file," or a similar name..

5. File Upload :


    • If the image is a file, the API may expect a file upload.
    • In this case, the multipart/form-data encoding is often used, allowing you to send files as part of the HTTP request.

6. Authentication:


    • If the API requires authentication, ensure that you include the necessary authentication tokens or credentials in your request headers.

7.Endpoint URL:


    • Ensure that you are sending the request to the correct endpoint URL.
    • The API documentation should provide the specific URL for image-related requests.

8.Response Handling:


    • Understand how the API responds to image-related requests.
    • The response may contain information about the processed image, error details, or other relevant data.

public string SendFCMNotification(string DeviceId, string Text, string SenderName, string path,string Img)
{
try
{ // Server key
var applicationID = "AAAAL5ULBwQ:APA91bGqwKGCWGgDehUEFxahofGCoZBlYAqAWX6dtnd3Ql2vypwU-Idn7rID087xX8HWlA4ETfnuSklCZvF_1lIa_xpR2HLQ-EC0YGS2ZPOP6JQLy58CYkAoanIPzVakjNaGr2VUAGy0";
// Sender Id
var senderId = "204363990788";
string deviceId = DeviceId;
var request = (HttpWebRequest)WebRequest.Create("https://fcm.googleapis.com/fcm/send");
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add(string.Format("Authorization: key={0}", applicationID));
request.Headers.Add(string.Format("Sender: id={0}", senderId));
var message = new
{
to = deviceId,
notification = new
{
body = Text,
title = SenderName,
//image = "https://www.kasandbox.org/programming-images/avatars/spunky-sam.png" image = Img
},
data = new
{
sound = "null"
channel_id = "null"
clickAction = path
}
};
var serializer = new JavaScriptSerializer();
var json = serializer.Serialize(message);
var byteArray = Encoding.UTF8.GetBytes(json);
request.ContentLength = byteArray.Length;
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var dataStreamResponse = response.GetResponseStream())
{
using (var reader = new StreamReader(dataStreamResponse))
{
string sResponseFromServer = reader.ReadToEnd();
return sResponseFromServer;
}
}
}
}
catch (Exception ex)
{
exp.ExceptionHandler(ex);
return "";
}
}
FrontEnd:
submit(value: any)
{
var obj = [{
BlogTitle: value.BlogTitle,
BlogImage: this.Photo,
ProductsInfo: value.ProductsInfo,
Benefits: value.Benefits,
Headers: value.Headers,
Discription: value.Discription
}]
this.Blogservice.AddBlog(obj).subscribe((data: any) => {
if (data === 'EXISTS')
{
this.general.presentAlert("Alert", "Your mobile number is already exists.")
// Handle the "EXISTS" response here
}
else if (data === 'SUCCESS')
{
var path = "blogdetails";
const massege = value.Discription+ ".";
var UploadFile = new FormData();
//const imageFile = new File([""], "ceo.webp", { type: "image/webp" });

UploadFile.append("message", massege);
UploadFile.append("senderName", value.BlogTitle);
UploadFile.append("Img", this.HomeURL+this.Photo);
UploadFile.append("Path", path);
var url = "api/Farmer/sendNotificationtoallFarmers";
this.general.PostData(url, UploadFile).subscribe((data: any) => {
debugger
});
this.NavCtrl.navigateForward('/blogdetails');
this.general.presentAlert("SUCCESS", "Your blog has been added successfully!.")
// Handle the "SUCCESS" response here
}
//this['NavCtrl'].navigateForward('/add-blog');
},
(err: any) => {
this.general.presentToast('Something went wrong. Please try again later.')
});
}

foot-logo

All design and content Copyright © 2012-2018 Gagri Global IT Services Pvt.Ltd. All rights reserved

Sitemap