Jump to content

Images not saving properly - ERROR 404 FetchRemote


.:HyPeX:.

Recommended Posts

Hello everyone i've found one issue with my custom downloading images from the forum (Avatars) system.

It fucks up alone when there is more than one player online and the images are saved with 5bytes. if i'm alone on the server it downloads my avatar perfectly.

Server:

  
  
local Database = dbConnect("mysql",***) 
  
gTable = {} 
  
  
addEventHandler('onPlayerLogin',root,function() 
local acc = getPlayerAccount(source) 
local acc = getAccountName(acc) 
local query = dbQuery(function(qh,player) 
local result = dbPoll(qh,0) 
local gvalue = 0 
setElementData(player, "member_id", result[1]["member_id"]) 
gvalue = result[1]["member_id"] 
local query = dbQuery(function(qh,player) 
local result = dbPoll(qh,0) 
id, photo = "","" 
id = result[1]["pp_member_id"] 
photo = result[1]["pp_main_photo"] 
if photo ~= "" then 
setElementData(player, "pp_main_photo", result[1]["pp_main_photo"]) 
else 
setElementData(player, "pp_main_photo", "profile/photo-0.jpg") 
end 
  
fetchImage(id, photo) 
  
end,{player},Database, "SELECT pp_member_id,pp_main_photo FROM profile_portal WHERE pp_member_id = '?'", gvalue) 
  
end,{source},Database, "SELECT member_id FROM members WHERE name='"..acc.."'") 
end) 
  
function fetchImage(id,photo) 
    fetchRemote ( "http://emp-clan.eu/uploads/"..photo, returnImage, "", false, id,photo ) 
end 
  
function returnImage(image, error, id, photo) 
    if fileExists("saved/"..photo) then 
    local file = fileOpen("saved/"..photo) 
    local size = fileGetSize(file) 
    local result = fileRead(file,size) 
    fileClose(file) 
    if result ~= image then 
    fileDelete("saved/"..photo) 
    local file = fileCreate("saved/"..photo) 
    fileWrite(file, image) 
    fileClose(file) 
    end 
    else 
    local file = fileCreate("saved/"..photo) 
    fileWrite(file, image) 
    fileClose(file) 
    end 
end 
  
addEvent("RequestAvatars",true) 
addEventHandler("RequestAvatars", root, function(player,id,photo,size) 
if size then 
   local file = fileOpen("saved/"..photo) 
   if size ~= fileGetSize(file) then 
        local info = fileRead(file,fileGetSize(file)) 
        fileClose(file) 
        triggerClientEvent(client,"SaveAvatars",resourceRoot,id,photo,info) 
    end 
    fileClose(file) 
else 
if fileExists("saved/"..photo) then 
    local file = fileOpen("saved/"..photo) 
        local info = fileRead(file,fileGetSize(file)) 
        fileClose(file) 
        triggerClientEvent(client,"SaveAvatars",resourceRoot,id,photo,info) 
    end 
    fileClose(file) 
end 
end) 
  

Client

  
  
addEventHandler('onClientResourceStart',root,function() 
for i,v in ipairs(getElementsByType("player")) do 
    local id = getElementData(v, "member_id") 
    local photo = getElementData(v, "pp_main_photo") 
    if photo then 
        if fileExists("saved/"..photo) then 
        local file = fileOpen("saved/"..photo) 
        local size = fileGetSize(file) 
        fileClose(file) 
        outputConsole(size) 
        triggerServerEvent("RequestAvatars", resourceRoot, localPlayer,id, photo, size) 
        else 
        triggerServerEvent("RequestAvatars", resourceRoot, localPlayer,id, photo) 
        end     
    end 
end 
end) 
  
addEvent('SaveAvatars',true) 
addEventHandler('SaveAvatars', root, function(id,photo,info) 
if info then 
    if fileExists("saved/"..photo) then 
    fileDelete("saved/"..photo) 
    local file = fileCreate("saved/"..photo) 
    fileWrite(file, info) 
    fileClose(file) 
    else 
    local file = fileCreate("saved/"..photo) 
    fileWrite(file, info) 
    fileClose(file) 
    end 
    setElementData(localPlayer, photo, true) 
end 
end) 
  
addEventHandler('onClientElementDataChange',root,function(name,old) 
if name == "pp_main_photo" then 
    local id = getElementData(source, "member_id") 
    local photo = getElementData(source, "pp_main_photo") 
        if photo then 
        if fileExists("saved/"..photo) then 
        local file = fileOpen("saved/"..photo) 
        local size = fileGetSize(file) 
        fileClose(file) 
        outputConsole(size) 
        triggerServerEvent("RequestAvatars", resourceRoot, localPlayer,id, photo, size) 
        else 
        triggerServerEvent("RequestAvatars", resourceRoot, localPlayer,id, photo) 
        end     
    end 
end 
end) 
  

Edited by Guest
Link to comment

No one? 100 views already...

I finally tracked down the issue to server side - The files are cut on 5byte. I tested checking if the files were cut by a request client-side - without client side, on player login a 5byte file is created.

I checked, it was a txt with "ERROR".

(Badly i didnt checked for error argument)

Error id is 215 - What is 215? Its not listed in the wiki.

EDIT: Error 215 was a wrong argument passed - i now get error 404 - even thought the file exists!

  
[url=http://emp-clan.eu/uploads/profile/photo-215.png]http://emp-clan.eu/uploads/profile/photo-215.png[/url] 
ERROR 404 215 
ERROR OBTAINING IMAGE. ERROR ID: 215 

  
  
function fetchImage(id,photo) 
outputChatBox("http://emp-clan.eu/uploads/"..photo) 
    fetchRemote ( "http://emp-clan.eu/uploads/"..photo, returnImage, "", false, id,photo ) 
end 
  
function returnImage(image, error, id, photo) 
outputChatBox(image.." "..error.." "..id) 
if errro ~= 0 then 
outputChatBox("ERROR OBTAINING IMAGE. ERROR ID: ".. id) 
else 
    if fileExists("saved/"..photo) then 
    local file = fileOpen("saved/"..photo) 
    local size = fileGetSize(file) 
    local result = fileRead(file,size) 
    fileClose(file) 
    if result ~= image then 
    fileDelete("saved/"..photo) 
    local file = fileCreate("saved/"..photo) 
    fileWrite(file, image) 
    fileClose(file) 
    end 
    else 
    local file = fileCreate("saved/"..photo) 
    fileWrite(file, image) 
    fileClose(file) 
    end 
end 
end 
  

Link to comment
  • 11 months later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...