본문으로 건너뛰기

파일 쓰기(RAW)

스트리밍 쓰기

  • API 설명

    PUT /write_file?filename=[URL 인코딩된 파일 이름] HTTP/1.1

    [파일 데이터]
    • 파일 바이트 스트림을 직접 받으며(base64로 인코딩되지 않음), 대용량 파일 업로드에 적합합니다
    • 대상 파일이 이미 있으면 덮어씁니다
  • 가능한 응답

    • 성공: HTTP 204, 응답 본문 없음
    • 실패:
      • HTTP 400 + {"message":"invalid path"}(filename이 제공되지 않았거나 경로가 올바르지 않음)
      • HTTP 404 + {"message":"invalid path"}(대상 경로를 만들 수 없음)
      • HTTP 500 + {"message":"…"}
  • API를 통해 기기의 스크립트 파일에 콘텐츠를 스트리밍 방식으로 쓰는 Python 3.x 예제(requests 모듈 필요):

    # -*- coding: utf-8 -*-
    import requests

    with open("r:/123.lua", "rb") as f:
    resp = requests.put("http://192.168.31.72:46952/write_file", params={"filename": "lua/scripts/123.lua"}, data=f, timeout=30)

    print(resp.status_code, resp.reason) # 성공 시 204 No Content
    if resp.status_code != 204:
    print(resp.text)

Base64 쓰기

  • API 설명

    POST /write_file HTTP/1.1

    {"filename":"파일 이름","data":"내용의 base64 인코딩 문자열"}
  • 가능한 응답

    {"code":0,"message":"操作成功"}
    {"code":4,"message":"无法写入文件"}
  • API를 통해 기기의 스크립트 파일에 콘텐츠를 쓰는 Python 3.x 예제(requests 모듈 필요):

    # -*- coding: utf-8 -*-
    import base64
    import requests

    with open('r:/123.lua', 'rb') as f: # 스크립트 파일 경로에서 바이트를 직접 읽음
    resp = requests.post(
    "http://192.168.31.72:46952/write_file",
    json={
    "filename": "lua/scripts/123.lua",
    "data": base64.b64encode(f.read()).decode('utf-8') # 바이트를 직접 base64로 인코딩
    },
    timeout=30,
    )

    print(resp.status_code, resp.reason) # 성공 시 200 OK
    print(resp.text)

참고

  • 이 API의 파일 작업 루트 디렉터리는 /var/mobile/Media/1ferver/입니다
  • 스트리밍 쓰기 API는 2025-07-11 이후 버전에서 사용할 수 있습니다