libURLMultipartFormAddPart

Typefunction
DictionaryLCS
LibraryLiveCode Script
Syntax
libURLMultipartFormAddPart(<formData>,<partName>, <value> [,<MIMEtype>, <encoding>])
Associationsinternet library
Summary

This function lets you add parts to a multipart form one at a time. It also lets you optionally specify the mime type and transfer encoding for each part. This can be useful where the mime type or transfer encoding has to be specified.

Introduced2.5
OSmac, windows, linux, web
Platformsdesktop, server
Parameters
NameTypeDescription
formData

A variable, which will be filled with the form data.

partName

The name of the new part to add to the formData.

value

The value to be associated with the partName of the formData.

MIMEtype

The MIME type to use for the value.

encoding

The encoding type to use for the value.

Example
command UploadFileToServer pName, pMessage, pFilename
  local tOrigHeaders, tForm, tError, tFile, tType, tEnc, tURL
  put the httpHeaders into tOrigHeaders
  put empty into tForm
  put libURLMultipartFormData (tForm, "name", pName, "message", pMessage) into tError

  if tError is empty then
    set the httpHeaders to line 1 of tForm
    delete line 1 of tForm
    put "<file>" & pFilename into tFile
    put "image/gif" into tType
    put "binary" into tEnc
    put libURLMultipartFormAddPart(tForm,"file", tFile, tType, tEnc) into tError
  end if

  if tError is empty then
    post tForm to url tURL
    put the result into tError
  end if

  set the httpHeaders to tOrigHeaders

  if tError is not empty then
    return tError for error
  else
    return empty for value
  end if
end UploadFileToServer
RelatedMessage: startup, openBackground, preOpenStack, openStack, preOpenCard
Command: post
Function: libURLMultipartFormData, libURLFormData
Glossary: LiveCode custom library, main stack, handler, Standalone Application Settings, message, group, standalone application, keyword, function, application
Library: Internet library, library
Securitynetwork
Description

This function is mainly used if you have called the libURLMultipartFormData with no arguments except the form data. This will return an "empty" form which can be added to using this function.

Important: The libURLMultipartFormAddPart function is part of the Internet library. To ensure that the function works in a standalone application, you must include this custom library when you create your standalone. In the Inclusions pane of the Standalone Application Settings window, make sure the "Internet" script library is selected.