Advertisement
Arc13

Cust Pastebin Put

Nov 5th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. local args = {...}
  2.  
  3. local function put( sFile )
  4.   assert( type( sFile ) == "string", "String expected, got " .. type( sFile ), 2)
  5.  
  6.   local sPath = sFile
  7.   assert( not fs.isDir( sPath ), "Cannot upload directories", 2 )
  8.  
  9.   local sName = fs.getName( sPath )
  10.   local handle = fs.open( sPath, "r" )
  11.   local sText = handle.readAll()
  12.   handle.close()
  13.   local key = "0ec2eb25b6166c0c27a394ae118ad829"
  14.   local response = http.post(
  15.     "http://pastebin.com/api/api_post.php",
  16.     "api_option=paste&" ..
  17.     "api_dev_key=" .. key .. "&" ..
  18.     "api_paste_format=lua&" ..
  19.     "api_paste_name=" .. textutils.urlEncode( sPath ) .. "&" ..
  20.     "api_paste_code=" .. textutils.urlEncode( sText )
  21.   )
  22.  
  23.   if response then
  24.     local sResponse = response.readAll()
  25.     local sCode = string.match( sResponse, "[^/]+$" )
  26.     response.close()
  27.     return sCode, true
  28.   end
  29.   return nil, false
  30. end
  31.  
  32. local code, success = put(args[1])
  33. print(code)
  34. print(success)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement