xtrime-ru / TelegramApiServer

Fast, simple, async php telegram api server: MadelineProto + Amp HTTP Server
https://tg.i-c-a.su
MIT License
534 stars 120 forks source link

downloadToResponse #66

Closed Maverick1983 closed 3 years ago

Maverick1983 commented 3 years ago

I use this step:

curl -H "Content-Type: multipart/form-data" -F "file=@upload/test.txt" 'http://127.0.0.1:9503/api/users/luca/uploadMediaForm'

Response

{ "success": true, "errors": [], "response": { "media": { "_": "inputMediaUploadedDocument", "file": { "_": "inputFile", "id": 5742225891161704365, "parts": 1, "name": "test.txt", "mime_type": "text/plain", "md5_checksum": "" }, "attributes": [ { "_": "documentAttributeFilename", "file_name": "test.txt" } ] } } }

After I want to download this file with this curl:

curl -H 'Content-Type: application/json' \ -d '{"media": {"_": "inputMediaUploadedDocument", "file": {"_": "inputFile", "id": 5742225891161704365, "parts": 1, "name": "test.txt", "mime_type": "text/plain","md5_checksum": ""},"attributes": [{"_": "documentAttributeFilename","file_name": "test.txt"}]}}' \ 'http://127.0.0.1:9503/api/users/luca/downloadToResponse'

But response is:

{ "success": false, "errors": [ { "exception": "danog\\MadelineProto\\Exception", "message": "Invalid constructor provided: inputMediaUploadedDocument", "file": "/app-host-link/vendor/danog/madelineproto/src/danog/MadelineProto/MTProtoTools/Files.php", "line": 760, "code": 0, "backtrace": [ { "file": "/app-host-link/vendor/danog/madelineproto/src/danog/MadelineProto/MTProtoTools/FilesLogic.php", "line": 154, "function": "getDownloadInfo", "class": "danog\\MadelineProto\\MTProto", "type": "->", "args": [ { "_": "inputMediaUploadedDocument", "file": { "_": "inputFile", "id": 5742225891161704365, "parts": 1, "name": "test.txt", "mime_type": "text/plain", "md5_checksum": "" }, "attributes": [ { "_": "documentAttributeFilename", "file_name": "test.txt" } ] } ] }, { "file": "/app-host-link/vendor/danog/madelineproto/src/danog/MadelineProto/AbstractAPIFactory.php", "line": 200, "function": "downloadToResponse", "class": "danog\\MadelineProto\\MTProto", "type": "->", "args": [ { "_": "inputMediaUploadedDocument", "file": { "_": "inputFile", "id": 5742225891161704365, "parts": 1, "name": "test.txt", "mime_type": "text/plain", "md5_checksum": "" }, "attributes": [ { "_": "documentAttributeFilename", "file_name": "test.txt" } ] }, {}, null, [] ] }, { "function": "__call_async", "class": "danog\\MadelineProto\\AbstractAPIFactory", "type": "->", "args": [ "downloadToResponse", [ { "_": "inputMediaUploadedDocument", "file": { "_": "inputFile", "id": 5742225891161704365, "parts": 1, "name": "test.txt", "mime_type": "text/plain", "md5_checksum": "" }, "attributes": [ { "_": "documentAttributeFilename", "file_name": "test.txt" } ] }, {}, null, [] ] ] } ] } ], "response": null }

xtrime-ru commented 3 years ago

Invalid constructor provided: inputMediaUploadedDocument

You need modify object. It need to be one of these types to allow download of it. https://docs.madelineproto.xyz/API_docs/types/MessageMedia.html

Also make sure you download uploaded document as fast as possible. They not stored for long if you not send them.

Maverick1983 commented 3 years ago

How can convert to MessageMedia?

Maverick1983 commented 3 years ago

I understand. You method 'uploadMediaForm' can use with sendMedia.

But I want to upload files to nobody, so I must use uploadMedia madelineProto function.

xtrime-ru commented 3 years ago

uploadMediaForm is same as uploadMedia. But it receives file from stream and not from disk/url. See sources: https://github.com/xtrime-ru/TelegramApiServer/blob/master/src/MadelineProtoExtensions/ApiExtensions.php#L530

Maverick1983 commented 3 years ago

No, because response it's different from uploadMedia with madelineProto. I test it and the response is:

{ "success": true, "errors": [], "response": { "": "messageMediaDocument", "document": { "": "document", "id": 6033076814786595189, "access_hash": 4862326786382995498, "filereference": { "": "bytes", "bytes": "AGB3a+kzA7QkdmYyAIWmJOhFlh60" }, "date": 1618439145, "mime_type": "text/plain", "size": 5, "dc_id": 4, "attributes": [] } } }

Il giorno gio 15 apr 2021 alle ore 09:57 Alexander Pankratov < @.***> ha scritto:

uploadMediaForm is same as uploadMedia. But it receives file from stream and not from disk/url. See sources: https://github.com/xtrime-ru/TelegramApiServer/blob/master/src/MadelineProtoExtensions/ApiExtensions.php#L530

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/xtrime-ru/TelegramApiServer/issues/66#issuecomment-820208716, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE43GZW2EUJ64BSYGL54GQDTI2L7ZANCNFSM42Y47XEA .