mLipok

CrowdinAPI UDF

6 posts in this topic

#1 ·  Posted (edited)

Today I want to present my current project.

This is UDF for   crowdin.net website API

In fact, not yet finished but functional.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#Tidy_Parameters=/sort_funcs /reel

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>


_Crowdin_Example_1()

Func _Crowdin_Example_1()
    Local $sACCOUNT_API_KEY = '...'
    Local $sPROJECT_API_KEY = '...'
    Local $sPROJECT_identifier = '...'
    Local $output = ''


    _Crowdin_Project_Identifier($sPROJECT_identifier)
    _Crowdin_Project_ApiKey($sPROJECT_API_KEY)
    _Crowdin_AccountKey($sACCOUNT_API_KEY)


    $output = _Crowdin_DirectoryCreate('Directory for testing CrowdinAPI')
    MsgBox(0, '_Crowdin_DirectoryCreate', $output)
    Exit

    $output = _Crowdin_GetProjectInfo()
    MsgBox(0, '_Crowdin_GetProjectInfo', $output)

    $output = _Crowdin_GetSupportedLanguages()
    MsgBox(0, '_Crowdin_GetSupportedLanguages', $output)

    $output = _Crowdin_TranslationExport()
    MsgBox(0, '_Crowdin_TranslationExport', $output)

    $output = _Crowdin_TranslationStatus()
    MsgBox(0, '_Crowdin_TranslationStatus', $output)

    $output = _Crowdin_TranslationDownload('all', @ScriptDir & '\Crowdin_test_DownloadTranslations.zip')

    $output = _Crowdin_GetProjects('mLipok')
    MsgBox(0, '_Crowdin_GetProjects', $output)

    $output = _Crowdin_DirectoryCreate('Directory for testing CrowdinAPI')
    MsgBox(0, '_Crowdin_DirectoryCreate', $output)


;~  $output =
;~  MsgBox(0, '', $output)

EndFunc   ;==>_Crowdin_Example_1

#Region CrowdinAPI - Functions

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_GetProjectInfo
; Description ...: Get Crowdin Project details.
; Syntax ........: _Crowdin_GetProjectInfo()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_GetProjectInfo()
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/info?key=' & _Crowdin_Project_ApiKey()
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_GetProjectInfo

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_GetSupportedLanguages
; Description ...:
; Syntax ........: _Crowdin_GetSupportedLanguages()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_GetSupportedLanguages()
    Local $sURL = 'https://api.crowdin.com/api/supported-languages'
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('GET', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_GetSupportedLanguages

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_TranslationExport
; Description ...:
; Syntax ........: _Crowdin_TranslationExport()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_TranslationExport()
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/export?key=' & _Crowdin_Project_ApiKey()
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('GET', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_TranslationExport


; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_TranslationStatus
; Description ...: Track your Crowdin project translation progress by language. Default response format is XML.
; Syntax ........: _Crowdin_TranslationStatus()
; Parameters ....:
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/status
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_TranslationStatus()
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/status?key=' & _Crowdin_Project_ApiKey()
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_TranslationExport


; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_TranslationDownload
; Description ...: Download ZIP file with translations. You can choose the language of translation you need or download all of them at once.
; Syntax ........: _Crowdin_TranslationDownload([$sPackage = 'all'[, $sZIP_FileFullPath = '']])
; Parameters ....: $sPackage            - [optional] a string value. Default is 'all'.
;                  $sZIP_FileFullPath   - [optional] a string value. Default is ''.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/download
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_TranslationDownload($sPackage = 'all', $sZIP_FileFullPath = '')
    ; GET https://api.crowdin.com/api/project/{project-identifier}/download/{package}.zip?key={project-key}
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/download/' & $sPackage & '.zip?key=' & _Crowdin_Project_ApiKey()
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('GET', $sURL, False)
    $oXmlHttp.Send()
    Local $output = $oXmlHttp.ResponseBody
;~  Local $type = $oXmlHttp.ResponseType
;~  MsgBox(0, VarGetType($type) & '='&$type&'=' , VarGetType($output))
;~  MsgBox(0, '', BinaryLen($output))

    If $sZIP_FileFullPath <> '' Then
        Local $hFile = FileOpen($sZIP_FileFullPath, $FO_OVERWRITE + $FO_BINARY)
        FileWrite($hFile, $output)
        FileClose($hFile)
    EndIf

    $oXmlHttp = ''
    Return $output

EndFunc   ;==>_Crowdin_TranslationDownload

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_GetProjects
; Description ...: Get Crowdin Project details.
; Syntax ........: _Crowdin_GetProjects($sLoginName)
; Parameters ....: $sLoginName              - A string value. Your Crowdin Account login name.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/get-projects
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_GetProjects($sLoginName)
    ; https://api.crowdin.com/api/account/get-projects?account-key={account-key}
    Local $sURL = 'https://api.crowdin.com/api/account/get-projects?account-key=' & _Crowdin_AccountKey() & '&login=' & $sLoginName
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send('')
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output
EndFunc   ;==>_Crowdin_GetProjects


; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_DirectoryCreate
; Description ...: Add directory to Crowdin project.
; Syntax ........: _Crowdin_DirectoryCreate($sDirectoryName)
; Parameters ....: $sDirectoryName      - A string value.
; Return values .: None
; Author ........: Your mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/add-directory
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_DirectoryCreate($sDirectoryName)
    ; https://api.crowdin.com/api/project/{project-identifier}/add-directory?key={project-key}
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-directory?key=' & _Crowdin_Project_ApiKey() & '&name=' & $sDirectoryName
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $oXmlHttp = ObjCreate("Microsoft.XMLHTTP")
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send('')
    Local $output = $oXmlHttp.ResponseText
    $oXmlHttp = ''
    Return $output
EndFunc   ;==>_Crowdin_GetProjects

#EndRegion CrowdinAPI - Functions

#Region CrowdinAPI - SETUP
; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_Project_ApiKey
; Description ...:
; Syntax ........: _Crowdin_Project_ApiKey([$vApiKey = Default])
; Parameters ....: $vApiKey             - [optional] a variant value. Default is Default.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/authentication
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_Project_ApiKey($vApiKey = Default)
    Local Static $sPROJECT_API_KEY = ''
    If $vApiKey = Default Then
        Return $sPROJECT_API_KEY
    Else
        $sPROJECT_API_KEY = $vApiKey
        Return $sPROJECT_API_KEY
    EndIf

EndFunc   ;==>_Crowdin_Project_ApiKey

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_Project_Identifier
; Description ...:
; Syntax ........: _Crowdin_Project_Identifier([$vIdentifier = Default])
; Parameters ....: $vIdentifier         - [optional] a variant value. Default is Default.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/authentication
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_Project_Identifier($vIdentifier = Default)
    Local Static $sPROJECT_identifier = ''
    If $vIdentifier = Default Then
        Return $sPROJECT_identifier
    Else
        $sPROJECT_identifier = $vIdentifier
        Return $sPROJECT_identifier
    EndIf

EndFunc   ;==>_Crowdin_Project_Identifier

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_AccountKey
; Description ...:
; Syntax ........: _Crowdin_AccountKey([$vAccountKey = Default])
; Parameters ....: $vAccountKey         - [optional] A variant value. Default is Default.
; Return values .: None
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/settings#user-profile-api-key
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_AccountKey($vAccountKey = Default)
    Local Static $sACCOUNT_API_KEY = ''
    If $vAccountKey = Default Then
        Return $sACCOUNT_API_KEY
    Else
        $sACCOUNT_API_KEY = $vAccountKey
        Return $sACCOUNT_API_KEY
    EndIf
EndFunc   ;==>_Crowdin_AccountKey
#EndRegion CrowdinAPI - SETUP

CrowdinAPI_v0.1.au3

 

have fun, 

mLipok

Edited by mLipok
1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm trying to finish this UDF.

I have problem with this function:

https://crowdin.com/page/api/add-file

Here is my current implementation:

; #FUNCTION# ====================================================================================================================
; Name ..........: _Crowdin_FileAdd
; Description ...: Add new file to Crowdin project that should be translated.
; Syntax ........: _Crowdin_FileAdd($sFileName[, $sTyp = 'auto'])
; Parameters ....: $sFileName           - a string value.
;                  $sTyp                - [optional] a string value. Default is 'auto'.
; Return values .: Response in XML format. For more info go to the followed link
; Author ........: mLipok
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........: https://crowdin.com/page/api/add-file
; Example .......: No
; ===============================================================================================================================
Func _Crowdin_FileAdd($sFileName, $sTyp = 'auto')
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp & '&files[' & $sFileName & ']>"' & @ScriptDir & '\' & $sFileName & ''
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp & '&files[' & @ScriptDir & '\' & $sFileName & ']=' & '%original_file_name%'
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp & '&files[' & $sFileName & ']=' & $sFileName
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp & '&files[' & $sFileName & ']'
;~  Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&files[' & $sFileName & ']'
    Local $sURL = 'https://api.crowdin.com/api/project/' & _Crowdin_Project_Identifier() & '/add-file?key=' & _Crowdin_Project_ApiKey() & '&type=' & $sTyp
    ConsoleWrite('! ' & $sURL & @CRLF)
    Local $sOutput = __Crowdin_POST($sURL, 'files[' & 'Plik1' & ']=@' & $sFileName)
    Return $sOutput

EndFunc   ;==>_Crowdin_FileAdd

 

For example I use it like in this following example :

$sOutput = _Crowdin_FileAdd(@ScriptDir & '\example.csv', 'csv')
    ClipPut($sOutput)
    MsgBox(0, '_Crowdin_FileAdd', $sOutput)

 And this function:

Func __Crowdin_POST($sURL, $sSendString = '')
    Local $oXmlHttp = ObjCreate($g__sClassName)
    ConsoleWrite("> $sURL: " & $sURL & @CRLF)
    ConsoleWrite("> $sSendString:" & $sSendString & @CRLF)
    $oXmlHttp.Open('POST', $sURL, False)
    $oXmlHttp.Send($sSendString)
    Local $sOutput = $oXmlHttp.ResponseText

    ; Clean Up
    $oXmlHttp = ''
    Return $sOutput

EndFunc   ;==>__Crowdin_POST

generates this Console Output:

Quote

$sURL: https://api.crowdin.com/api/project/testingapi/add-file?key=2dc8c1f4........6d629&type=csv
$sSendString:files[Plik1]=@Z:\Crowdin_API\example.csv

 

but I'm getting this following message from the API:

<?xml version="1.0" encoding="ISO-8859-1"?>
<error>
  <code>4</code>
  <message>No files specified in request</message>
</error>

Can somebody help to show me what I'm doing wrong ?

 


EDIT:  Basicly:
I have problem with implementing this:

https://crowdin.com/page/api/add-file

Name Value Description
filesrequired array Files array that should be added to Crowdin project. Array keys should contain file names with path in Crowdin project. 
Note! 20 files max are allowed to upload per one time file transfer.
Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

You likely need multipart/form-data. That's like when filling the form that uploads file(s).


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks @trancexx

Some searching and I found this:

 

http://lists.alioth.debian.org/pipermail/pkg-mozext-commits/2014-July/005861.html
https://github.com/EFForg/trackerlab/blob/master/buildtools/localeTools.py

def postFiles(files, url):
  boundary = '----------ThIs_Is_tHe_bouNdaRY_$'
  body = ''
  for file, data in files:
    body += '--%s\r\n' % boundary
    body += 'Content-Disposition: form-data; name="files[%s]"; filename="%s"\r\n' % (file, file)
    body += 'Content-Type: application/octet-stream\r\n'
    body += 'Content-Transfer-Encoding: binary\r\n'
    body += '\r\n' + data + '\r\n'
  body += '--%s--\r\n' % boundary

  body = body.encode('utf-8')
  request = urllib2.Request(url, StringIO(body))
  request.add_header('Content-Type', 'multipart/form-data; boundary=%s' % boundary)
  request.add_header('Content-Length', len(body))
  result = urllib2.urlopen(request).read()
  if result.find('<success') < 0:
    raise Exception('Server indicated that the operation was not successful\n' + result)

I think this is it, or something similar ....

So its time to practice - back to work on it.
See you later.

 

Edited by mLipok
1 person likes this

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

3 hours ago, mLipok said:

body += '--%s\r\n' % boundary    
body += 'Content-Disposition: form-data; name="files[%s]"; filename="%s"\r\n' % (file, file)

I'm not familiar to python, so maybe somebody can confirm:  Whethter this %s is some kind of StringFormat() ?

 

EDIT:
now I'm looking for "application/octet-stream" , just here 

 

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

I found the answer.

Thanks again @trancexx


Soon I'll update the entire UDF.

The following snippet showing preliminary solution to the problem.

Func __Crowdin_POST($sURL, $sSendString = '', $sFile = Default, $sCrowdinFileWithPath = Default, $sCrowdinName = Default)
    Local $oXmlHttp = ObjCreate($g__sClassName)
    $oXmlHttp.Open('POST', $sURL, False)

    If Not ($sFile = Default) And FileExists($sFile) Then
        Local $sBoundary = '----------ThIs_Is_tHe_bouNdaRY_$'
        Local $sBody = ''
        $sBody &= '--' & $sBoundary & @CRLF
        $sBody &= StringFormat('Content-Disposition: form-data; name="files[%s]"; filename="%s"', $sCrowdinFileWithPath, $sCrowdinName) & @CRLF
        $sBody &= 'Content-Type: application/octet-stream' & @CRLF
        $sBody &= 'Content-Transfer-Encoding: binary' & @CRLF
        Local $dBinary = FileRead($sFile)
        $sBody &= @CRLF & $dBinary & @CRLF
        $sBody &= '--' & $sBoundary & '--' & @CRLF

        $oXmlHttp.SetRequestHeader('Content-Type', 'multipart/form-data; boundary=' & $sBoundary)
        $oXmlHttp.SetRequestHeader('Content-Length', StringLen($sBody))
        $oXmlHttp.Send($sBody)
    Else
        $oXmlHttp.Send($sSendString)
    EndIf

    Local $sOutput = $oXmlHttp.ResponseText

    #cs
        Local $aOutput[$__g_iOutput_ENUMCOUNTER]
        $aOutput[$__g_iOutput_Status] = String($oXmlHttp.Status)
        $aOutput[$__g_iOutput_StatusText] = $oXmlHttp.StatusText
        $aOutput[$__g_iOutput_AllResponseHeaders] = $oXmlHttp.GetAllResponseHeaders()
        $aOutput[$__g_iOutput_ResponseText] = $oXmlHttp.ResponseText
        _ArrayDisplay($aOutput)

    #ce

    ; Clean Up
    $oXmlHttp = ''
    Return $sOutput

EndFunc    ;==>__Crowdin_POST

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • mLipok
      By mLipok
      I am in the process of creating a UDF for CrowdinAPI. I have a problem with one function.   https://crowdin.com/page/api/get-projects     This is my implementation. Func _Crowdin_GetProjects() ; https://api.crowdin.com/api/account/get-projects?account-key={account-key} Local $sURL = 'https://api.crowdin.com/api/account/get-projects?account-key=' & _Crowdin_AccountKey() ConsoleWrite('! ' & $sURL & @CRLF) Local $oXmlHttp = ObjCreate("MSXML2.XMLHTTP.3.0") $oXmlHttp.Open('POST', $sURL, False) $oXmlHttp.Send() Local $output = $oXmlHttp.ResponseText $oXmlHttp = '' Return $output EndFunc ;==>_Crowdin_GetProjects Func _Crowdin_AccountKey($vAccountKey = Default) Local Static $sACCOUNT_API_KEY = '' If $vAccountKey = Default Then Return $sACCOUNT_API_KEY Else $sACCOUNT_API_KEY = $vAccountKey Return $sACCOUNT_API_KEY EndIf EndFunc ;==>_Crowdin_AccountKey I do not know how to use: login={crowdin-login-name}
      curl -F "login={crowdin-login-name}" https://api.crowdin.com/api/account/get-projects?account-key={account-key} Thank you in advance for any help.
      mLipok